• I was wondering how i can apply different css styling to the last 4 posts of a wordpress blog that has a total of 6 maximum posts being shown on the front page.

    The first 2 posts are going to be a “large” version preview of the post and the next 4 are going to be a “small” version preview of the actual post.

    Is there a way in wordpress to number the first posts 1 through 6? And i can just drop that number into the css styling.

    Or is there a more elegant way of doing it? maybe with a wordpress function?

Viewing 2 replies - 1 through 2 (of 2 total)
  • <?php $c = 0;
    if (have_posts()) : while (have_posts()) : the_post();
    $c++;
    if($c < 3) $style='large';
    else $style='small;
    ?>
    <div <?php post_class($style);?> id="post-<?php the_ID();?>">

    Should add the class “large” to the first 2 posts and “small” to post 3 onwards.

    Thread Starter ch4sethe5un

    (@ch4sethe5un)

    thank you! i tried the post_class() and it also puts a lot of clutter in the class that i dont want, so i just echoed out $style. Thanks again.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘apply different style to last 4 posts’ is closed to new replies.