【问题标题】:Uncaught Error: Call to undefined function have_post()未捕获的错误:调用未定义的函数 have_post()
【发布时间】:2017-07-25 19:58:24
【问题描述】:

我正在尝试查看我的 WordPress 主题并收到此错误:

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

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; ?>

我该如何解决?

【问题讨论】:

  • 问题不在于 index.php 本身,而是对 the_content 的调用在内部调用了一个不存在的函数 have_post()。 (或者可能没有包含在上下文中。)

标签: wordpress


【解决方案1】:

试试have_posts(),而不是你的have_post()

还将the_autor_posts_link() 更改为the_author_posts_link()

<?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; ?>

【讨论】:

    【解决方案2】:

    这样写你的代码:

    <?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
        }
    ?>
    

    【讨论】:

      猜你喜欢
      • 2018-09-22
      • 2019-04-02
      • 2016-04-09
      • 2020-04-29
      • 2017-07-15
      • 2022-06-14
      • 2017-01-17
      • 2018-12-08
      • 2016-08-13
      相关资源
      最近更新 更多