Support » Themes and Templates » Recent Post and 4 Recent Displayed Different than Rest

  • 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 (2×2), 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!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Michael

    (@alchymyth)

    Forum Moderator

    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;

    Excellent, I will try that out. Thank you!

    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!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Recent Post and 4 Recent Displayed Different than Rest’ is closed to new replies.