Jesusmbm17
Jesusmbm17

Reputation: 13

Uncaught Error: Call to undefined function have_post()

I am trying to make a look on my WordPress theme and I received this error:

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

How can I fix it?

Upvotes: 1

Views: 8855

Answers (2)

ashanrupasinghe
ashanrupasinghe

Reputation: 756

Try have_posts() instead of your have_post().

Also change the_autor_posts_link() to 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; ?>

Upvotes: 7

Dhruvin Moradiya
Dhruvin Moradiya

Reputation: 546

Write your code like this:

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

Upvotes: 1

Related Questions