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.

Here is the loop from my author.php page. It is showing recent posts, but not the MOST recent.

Where is my mistake?

    <?php if (have_posts()): the_post(); ?>
        <h3>
            <?php _e('All posts by'); ?> <?php echo get_the_author(); ?>
            <span class="arrows">&raquo;</span>
        </h3>

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

    <div id="post-<?php the_ID(); ?>" class="cat-post">
    <div class="cat-post-left">
        <a href="<?php the_permalink() ?>" title="<?php bloginfo('name'); ?> - <?php bloginfo('description'); ?> - <?php the_title(); ?>"><?php the_post_thumbnail( '300x169' ); ?></a>
        <div class="meta-box">
        <div class="post-meta">
<div class="line"><cite>By &nbsp;<span class="plus-icon"><?php the_author_posts_link(); ?></span></cite><span><?php the_date(); ?></span></div>
</div>
</div>
</div>
            <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php bloginfo('name'); ?> - <?php bloginfo('description'); ?> - <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
                <?php the_excerpt(); ?>
                <a class="continue-reading" href="<?php the_permalink(); ?>">Read on &raquo;</a>
            </div>

Here is the site. The "Editor's Pick" post on the homepage is the most recent and does not show up on the Author page.

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

The mistake is in your first block of code:

<?php if (have_posts()): the_post(); ?>
    <h3>
        <?php _e('All posts by'); ?> <?php echo get_the_author(); ?>
        <span class="arrows">&raquo;</span>
    </h3>

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

You call the_post() to populate the regular template tags (i.e. get_the_author()) but don't use the rest of the post. Then, inside your while loop, you call the_post() to populate these template tags with the next post in the result set.

Instead, you need to handle the first post in that first block as well. Change your code to something like this:

<?php if (have_posts()): the_post(); ?>
    <h3>
        <?php _e('All posts by'); ?> <?php the_author(); ?>
        <span class="arrows">&raquo;</span>
    </h3>

    <!-- markup for first post -->
    <div id="post-<?php the_ID(); ?>" class="cat-post">
        <div class="cat-post-left">
            <a href="<?php the_permalink() ?>" title="<?php bloginfo('name'); ?> - <?php bloginfo('description'); ?> - <?php the_title(); ?>"><?php the_post_thumbnail( '300x169' ); ?></a>
            <div class="meta-box">
                <div class="post-meta">
                    <div class="line"><cite>By &nbsp;<span class="plus-icon"><?php the_author_posts_link(); ?></span></cite><span><?php the_date(); ?></span></div>
                </div>
            </div>
        </div>

        <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php bloginfo('name'); ?> - <?php bloginfo('description'); ?> - <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
        <?php the_excerpt(); ?>
        <a class="continue-reading" href="<?php the_permalink(); ?>">Read on &raquo;</a>
    </div>

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

    <!-- markup for subsequent posts -->
    <div id="post-<?php the_ID(); ?>" class="cat-post">
        <div class="cat-post-left">
            <a href="<?php the_permalink() ?>" title="<?php bloginfo('name'); ?> - <?php bloginfo('description'); ?> - <?php the_title(); ?>"><?php the_post_thumbnail( '300x169' ); ?></a>
            <div class="meta-box">
                <div class="post-meta">
                    <div class="line"><cite>By &nbsp;<span class="plus-icon"><?php the_author_posts_link(); ?></span></cite><span><?php the_date(); ?></span></div>
                </div>
            </div>
        </div>

        <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php bloginfo('name'); ?> - <?php bloginfo('description'); ?> - <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
        <?php the_excerpt(); ?>
        <a class="continue-reading" href="<?php the_permalink(); ?>">Read on &raquo;</a>
    </div>
share|improve this answer
add comment

This might be better handled with using rewind_posts();. I've used this to get around this problem recently, and it's worked well. It simply rewinds the loop back to the first post (http://codex.wordpress.org/Function_Reference/rewind_posts).

I've suggested (untested) code below.

<?php rewind_posts(); ?>
<?php if (have_posts()): the_post(); ?>
    <h3>
        <?php _e('All posts by'); ?> <?php echo get_the_author(); ?>
        <span class="arrows">&raquo;</span>
    </h3>

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

<div id="post-<?php the_ID(); ?>" class="cat-post">
<div class="cat-post-left">
    <a href="<?php the_permalink() ?>" title="<?php bloginfo('name'); ?> - <?php bloginfo('description'); ?> - <?php the_title(); ?>"><?php the_post_thumbnail( '300x169' ); ?></a>
    <div class="meta-box">
    <div class="post-meta">
<div class="line"><cite>By &nbsp;<span class="plus-icon"><?php the_author_posts_link(); ?></span></cite><span><?php the_date(); ?></span></div>
</div>
</div>
</div>
            <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php bloginfo('name'); ?> - <?php bloginfo('description'); ?> - <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
                <?php the_excerpt(); ?>
                <a class="continue-reading" href="<?php the_permalink(); ?>">Read on &raquo;</a>
        </div>
share|improve this answer
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.