0

I am working on my category template. Here is how I want the page to display:

  1. Category Name - this is done
  2. The latest post for each category be on top (then styled which I can do).
  3. The Category description - this is done
  4. List all the rest of the posts for the category under it - I can list all the posts, but I want to skip the latest

Any help in pointing me in the right direction, I would appreciate it. Thanks

2 Answers 2

1

Use WP_Query's built in current_post counter in your loop:

while( have_posts() ):
    the_post();
    if( $wp_query->current_post == 0 ):
        // this is the first post in the loop
    else:
        // this is > first post
    endif;
endwhile;

EDIT w/html:

<?php
while( have_posts() ):
    the_post();
    if( $wp_query->current_post == 0 ):
        ?>
        featured post

        category description

        <ul>
        <?php
    else:
        ?>
        <li>post</li>
        <?php
    endif;
endwhile;
?>
</ul>
2
  • How does that work with putting code in between? I want to put the description after the first post and an ul list around the n+1 posts.
    – Martin
    Commented May 7, 2012 at 16:38
  • @Martin see edit above
    – Milo
    Commented May 7, 2012 at 16:49
0

Create a $counter variable (that equals 0 at the beginning) outside of the posts loop. Increment the variable by 1 in the loop. Again, inside the loop check if the counter is 0, if yes - do nothing, if it's bigger than 0 - show the post. :)

1
  • Show how do I get the latest post for the category? Run the loop twice?
    – Martin
    Commented May 7, 2012 at 15:43

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.