Reputation: 887
I have the following code (leaving out everything before and after to start with):
<?php query_posts( 'posts_per_page=4' ); ?>
<?php
if ( have_posts() )
the_post();
?>
<?php while ( have_posts() ) : the_post(); ?>
<h2><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
<?php twentyten_posted_on(); ?>
<?php the_excerpt(); ?>
<p><?php printf( __( 'Posted in %2$s', 'twentyten' ), 'entry-utility-prep entry-utility-prep-cat-links', get_the_category_list( ', ' ) ); ?></p>
<p><?php comments_popup_link( __( 'Leave a comment', 'twentyten' ), __( '1 Comment', 'twentyten' ), __( '% Comments', 'twentyten' ) ); ?></p>
<?php comments_template( '', true ); ?>
<?php endwhile; ?>
The resulting page doesn't show the 4 most recent posts - it is dropping the most recent post. Here is the live page:
Here is another page (using the standard loop archive code) showing the 4 most recent posts.
http://www.metricit.com/category/blog/
What have I done wrong?
Thanks
Brett
Upvotes: 0
Views: 664
Reputation: 30021
My guess is that you should remove the first call to the_post()
, try changing your code to this:
<?php query_posts( 'posts_per_page=4' ); ?>
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<h2><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
<?php twentyten_posted_on(); ?>
<?php the_excerpt(); ?>
<p><?php printf( __( 'Posted in %2$s', 'twentyten' ), 'entry-utility-prep entry-utility-prep-cat-links', get_the_category_list( ', ' ) ); ?></p>
<p><?php comments_popup_link( __( 'Leave a comment', 'twentyten' ),__( '1 Comment', 'twentyten' ), __( '% Comments', 'twentyten' ) ); ?></p>
<?php comments_template( '', true ); ?>
<?php endwhile; ?>
<?php endif; ?>
Upvotes: 1
Reputation: 6532
Why do you have this above your loop?
<?php
if ( have_posts() )
the_post();
?>
Get rid of it - that's skipping the first post.
Upvotes: 2