How To Set Different Style For Latest Post In WordPress

Posted by


You can find many blogs which has assigned special style to latest post at his blog. In order to apply the different style on latest posts you need perform this procedure:

1) Need to edit the index.php file of your theme. Search this code in index.php:

while (have_posts()) : the_post();

After this code add this code in index file:

<?php if (is_paged()) : ?>
<?php $postclass = (‘post’); ?>
<?php else : ?>
<?php $postclass = ($post == $posts[0]) ? ‘featured-post’ : ‘post’; ?>
<?php endif; ?>

As you can see from above code defines $postclass as a variable and look for the latest post and assign that variable to a new name. Now, you need to output that variable where your post has the CSS style assigned to it. See the example below:

<h3><a href=”<?php the_permalink() ?>” rel=”bookmark”><?php the_title(); ?></a></h3>

Now, you need to set the style in CSS file according to the class name you have assigned for the latest post.

That’s it!


Shane G.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.