treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Most recent post plugin with title, date & excerpt.

  • I am looking for a wordpress plugin OR just a way to do the following.

    I want on the home page an area that lists off the 2 or 3 most recent post. I want it to show the Title and date as well as the text that is put into the excerpt field of the posts. Does anyone know of how I can do this?

    The closest i have found is a plugin called "Recent Posts with Excerpts " It works great but does NOT have the date. wonder if I could modify this! I know how to get the PHP for the date in there.. but dont know how to have it tie in to displaying of the 3 most recent posts.
  • No need for a plugin here, super simple loop! It'll look something like this:

    <?php query_posts('posts_per_page=3'); ?>

    <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>

    <h2><a href=\"<?php the_permalink(); ?>\"><?php the_title(); ?></a></h2>
    <p class=\"date\">Posted on: <?php the_date(); ?></p>

    <?php the_excerpt(); ?>

    <?php endwhile; ?>
  • Thanks so much! that worked great.

    I am now wanting to put a link to ...read more. and am having a tough time getting it placed right after the (.) at the end of each excerpt/.
    The way this loop works it seem to automatically put <p> tags around the excerpt and I dont know where to find that to add this snippet of code for "read more" Does that make sense?

    When I put it in there it puts in below everything of that excerpt and pushes down into the next one. I want it to flow right with the text of the excert but just be a link like you see most of the time.
  • You could try doing this, though I haven't tested it:

    <p><?php wp_trim_excerpt() ?> - <a href=\"<?php the_permalink(); ?>\">Your Read More Text...</a></p>