WordPress.org

Ready to get started?Download WordPress

Forums

Show recent posts on a list and single out 1st item for special formating (2 posts)

  1. edgarsso
    Member
    Posted 5 years ago #

    I am working on my WordPress theme and I was wondering how I can setup a loop so it displays the excerpts of the most recent posts from category but separate the very most recent post so I can format it differently (make it stand out from the rest of list of posts).

    I am working on a Magazine like format so the most recent article from say Science will be displayed bigger and for the rest I want to show them smaller. I can do the formatting for CSS just fine with no sweat but the loop code is what trouble me.

    I was able to pull the most recent post list with the code displayed here (Codex > Loop) but how can single out the very first item so I can format it differently?
    Any ideas? any help is much appreciated!

  2. stvwlf
    Member
    Posted 5 years ago #

    hi

    Some code I came up with yesterday along that line. This goes inside a WP loop

    <?php
    if( ($wp_query->current_post == 0) && !isset($wp_query->query[paged])) ) {
                    ===== code for first post =======
    } else {
                    ===== code for the rest of the posts =======
    }
    ?>

    explanation:
    $wp_query-> current_post == 0 means the first post in the current page

    !isset($wp_query->query[paged])) if that is true it means we are on the first page of posts, in case we have a set of post pages. Without that, the 1st post code would be applied to the 1st post on every page in the set, whereas we only want it applied to the first post of page 1 in a possible set.

Topic Closed

This topic has been closed to new replies.

About this Topic