1

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!

EDIT

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

1 Answer 1

1

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

3
  • 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.
    Commented Mar 21, 2013 at 20:28
  • Please show your code for this version.
    – vancoder
    Commented Mar 21, 2013 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.
    Commented Mar 21, 2013 at 20:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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