Problems with loop

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

Read More
<?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?

Related posts

1 comment

  1. 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();
    

Comments are closed.