2017-03-06 92 views
1

我試圖讓我的WordPress主題一看,我收到此錯誤:未捕獲的錯誤:調用未定義功能have_post()

Fatal error: Uncaught Error: Call to undefined function have_post() in C:\xampp\htdocs\wordpress\wp-content\themes\ChachoTheme\index.php:6 Stack trace: #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} thrown in C:\xampp\htdocs\wordpress\wp-content\themes\ChachoTheme\index.php on line 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; ?> 

哪有我修復它?

+0

問題並不在index.php文件本身,而是一個調用'the_content'內部調用一個不存在的函數'have_post()'。 (或可能未包含在上下文中。) –

回答

1

寫你這樣的代碼:

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

謝謝,yoor幫助非常感謝。 – Jesusmbm17

3

嘗試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; ?> 
+0

感謝您的幫助,其工作 – Jesusmbm17

相關問題