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?
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:You want to change the order and move it before the output of any of the other template tags: