WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I created an archive page called archive.php

Here I include header / footer and this code:

<?php if (have_posts()) : while (have_posts()) : ?>
              <h1 class="entry-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?><a/></h1>
              <?php the_post(); the_content();  ?>
              <br />
<?php endwhile; endif; ?>

The problem is that when there are more posts for a month, the first two posts have the title and permalink of the first post. How can I fix this?

Anticipated thanks!


Good advice toscho.

I fixed it, here's the solution:

<?php while(have_posts()) : the_post(); ?>

<h1 class="entry-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?><a/></h1>
<?php the_content(); ?><br />

<?php endwhile; ?>
share|improve this question
up vote 1 down vote accepted

You have to call the_post(); before you use the_permalink() or the_title(). Both functions work with a global $post object that will be set up by the_post();.

share|improve this answer
I tried this also, but in this case it won't appear all the posts from the chosen month. For example: from 3 posts one is displayed, or from 6 posts 3 are displayed.. how to fix this? – Rares P. Mar 21 '13 at 20:28
Please show your code for this version. – vancoder Mar 21 '13 at 20:48
I fixed it, I updated my question, see there the final solution. Thanks toscho (I can't mark your question as useful because of my low score :D ) – Rares P. Mar 21 '13 at 20:58

Your Answer


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.