WordPress.org

Ready to get started?Download WordPress

Forums

Recent Post and 4 Recent Displayed Different than Rest (4 posts)

  1. Connor Crosby
    Member
    Posted 3 years ago #

    I am making a theme and I want the most recent post to be laid out differently than the other posts. Also, I want recent posts 2 through 4 to have a different layout from the first and older posts.

    Basically, I want the first post to have a featured image, full-width, and have larger font. Then posts 2 through 4 will have a smaller featured image, 50% width (2x2), and smaller font. All other posts (5+) will have no featured image, 100% width, and small font (like posts 2-4).

    How can I achieve this through WordPress tags / PHP? I know how to style it in CSS. Thank you very much!

  2. alchymyth
    Forum Moderator
    Posted 3 years ago #

    using a counter inside the loop is a common way to do this.

    principle:

    if (have_posts()) : $counter=1;
       while (have_posts()) :
          the_post();
    if($counter==1) { /*php to show everything for post 1 */ }
    elseif($counter<1 && $counter<=5) { /*php to show everything for post 2to5 */ }
    else { /*php to show all the rest */ }
         $counter++;   endwhile;
    endif;
  3. Connor Crosby
    Member
    Posted 3 years ago #

    Excellent, I will try that out. Thank you!

  4. Connor Crosby
    Member
    Posted 3 years ago #

    I still haven't tried that yet, but I have another question.

    How can I change the limit of the excerpt? For example, I'd like the first post to have an excerpt limit of 150 words and the other posts have a limit of 75 words. Thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic