当前位置: 首页 > 知识库问答 >
问题:

未捕获的错误:调用未定义的函数have_post()

沈国安
2023-03-14

我想看看我的WordPress主题,我收到了这个错误:

致命错误:未捕获错误:调用未定义的函数have_post()在C:\xampp\htdocs\wordpress\wp-内容\主题\ChachoTheme\index.php: 6堆栈跟踪:#0 C:\xampp\htdocs\wordpress\wp-包括\template-loader.php(74):包括()#1 C:\xampp\HTDocs\wordpress\wp-blog-header.php(19):require_once('C:\xampp\htdocs...')#2 C:\xampp\htdocs\wordpress\index.php(17):要求('C:\xampp\htdocs...')#3{main}在第6行的C中抛出:\xampp\htdocs\wordpress\wp-内容\主题\ChachoTheme\index.php

index.php:

<?php if (have_post() ):?>
  <?php while(have_post()):the_post(); ?>

<div id="post">

  <h2><a href="<?php the_permalink(); ?>"></a><?php the_title(); ?></h2>
  <div class="byline">Escrito por <?php the_autor_posts_link(); ?>
    el <a href="<?php the_permalink(); ?>"><?php the_time('l F d, Y'); ?></a>
  </div>
  <?php the_content('Read More..'); ?>
<?php endwhile; ?>
<?php else: ?>
  <p>No posts were found. Sorry!")</p>
<?php endif; ?>

我怎样才能修好它?

共有2个答案

颜云瀚
2023-03-14

按如下方式编写代码:

<?php
    if ( have_posts() ) {
        while ( have_posts() ) {
?>
            <div id="post">
                <h2><a href="<?php the_permalink(); ?>"></a><?php the_title(); ?></h2>
                <div class="byline">Escrito por <?php the_autor_posts_link(); ?> el <a href="<?php the_permalink(); ?>"><?php the_time('l F d, Y'); ?></a></div>
                <?php the_content('Read More..'); ?>
            </div>

<?php
        }
    }
    else { ?>
        <p>No posts were found. Sorry!")</p>

<?php
    }
?>
穆浩皛
2023-03-14

尝试have_post()而不是have_post()

同时将自动发布链接()更改为作者发布链接()

<?php if (have_posts() ):?>
  <?php while(have_posts()):the_post(); ?>

<div id="post">

  <h2><a href="<?php the_permalink(); ?>"></a><?php the_title(); ?></h2>
  <div class="byline">Escrito por <?php the_author_posts_link(); ?>
    el <a href="<?php the_permalink(); ?>"><?php the_time('l F d, Y'); ?></a>
  </div>
  <?php the_content('Read More..'); ?>
<?php endwhile; ?>
<?php else: ?>
  <p>No posts were found. Sorry!")</p>
<?php endif; ?>
 类似资料: