Blog > Website Design > Recent Post With Excerpt Then Display Titles In WP

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.

Posted by : Dinusha | Apr 21, 2009

One Response to “Recent Post With Excerpt Then Display Titles In WP”

  1. Montana Flynn Says:
    1

    Thanks for this wonderful code!

Leave a Reply

Name (required)

Mail (will not be published) (required)

Website

Blog Categories

Posts + Podcasts

Podcast Feeds

Design Portfolio

Design Services