Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have this loop in my index.php:

      <?php if (have_posts()) :
          while (have_posts()) :
            get_template_part( 'post' );
          endwhile;
        endif; ?>

which calls this template

<?php   
 ?>
 <h2 id="post-<?php the_ID(); ?>">
 <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
 <?php the_title(); ?></a></h2>
 <?php the_post();
 the_content(); ?>
 <p class="date"><?php the_time('l, j F Y'); ?> </p>
 <?php trackback_rdf();
?>

The loop behaves strangely printing out titles and posts in this order:

  • Title post #1
  • Content post #1 (and this is ok, but then...)

  • Title post #1

  • Content post #2

  • Title post #2

  • Title post #3 (and so on...)

What am I doing wrong?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

the_post() function is what advances the internal counter and loads the data for the next post. You're calling it between the title and content:

the_title();
the_post();
the_content();

You want to change the order and move it before the output of any of the other template tags:

the_post();
the_title();
the_content();
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.