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; ?>
You have to call
the_post();
before you usethe_permalink()
orthe_title()
. Both functions work with a global$post
object that will be set up bythe_post();
.