This WordPress code will display your recent posts in two different formats. First It will display the most recent post with it’s excerpt or full content, then display just the remaining recent post titles.
You can format this with CSS (Cascading Style Sheets) to make it look like a newspaper format display or news site like CNN, etc. Maybe add a custom field image to make it prettier.
Code Demo Look
To see how this code will look like with some CSS styles applied and post image added , look at the post image on top of this page.
WordPress Code
<?php if (have_posts()) : ?> <?php $count = 0; ?> <?php while (have_posts()) : the_post(); ?> <?php $count++; ?> <?php if ($count <= 1) : ?> <h2><a class="permalink" href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"> <?php the_title(); ?></a></h2> <?php the_excerpt(); ?> <?php else : ?> <h2><a class="permalink" href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"> <?php the_title(); ?></a></h2> <?php endif; ?> <?php endwhile; ?> <?php else : ?> <?php endif; ?>
Code Modifications
Display more than 1 most recent post – See this line in the code. <?php if ($count <= 1) : ?> It is set it 1, but you can Increase the number to whatever you like.
Display Excerpt or Content – By default this is set to <?php the_excerpt(); ?> which output the post excerpt for the first post, but you can set it up as <?php the_content(); ?> to display the full post content.
Where To Put The Code
This will go inside any of your WordPress Template files inside your Themes directory. Ex: singles.php, archives.php, or your own custom template file.





October 1st, 2009 at 7:55 am
Thanks for this wonderful code!