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 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; ?>
share|improve this question
add comment

1 Answer 1

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
add comment

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.