• I use the code: <?php wp_get_archives(‘type=postbypost&limit=4’); ?> to list the 4 most recent posts, but I’d also like to be able to list the excerpt after each post. Is there a way to do this and if so, how? Any help is appreciated.

Viewing 4 replies - 1 through 4 (of 4 total)
  • I would also like to know how to do this. If anyone knows a simple way it would be much appreciated

    cheers,

    I think the best way to do it would be, instead, to use a WP_Query object to create a secondary loop on the page. Something like this:

    <?php
    $recent = new WP_Query();
    $recent->query('showposts=4');
    if($recent->have_posts()) : while($recent->have_posts()): $recent->the_post();
    ?>
    <!--whatever html structure you want to put here to get the_title() the_permalink() and the_excerpt() for each of the members of $recent->the_post()-->
    <?php endwhile ?>
    <?php else : ?>
    <p> Nothing to see here. Move along </p>
    <?php endif ?>

    That’s how I’d do it.

    Hi guys. I’m using this method, but I’m getting some strange results. The date is appearing only on the first entry retrieved (you can see it here – https://www.mattkeefe.com/living_static/ – second block down the sidebar). Why would this be the case? Do I need to move my <ul> and <li> tags? My PHP is below. Cheers.

    <div id="recent_posts">
    
    						<h3>Recent Posts</h3>
    						<ul class="posts">
    <?php
    $recent = new WP_Query();
    $recent->query('showposts=4');
    if($recent->have_posts()) : while($recent->have_posts()): $recent->the_post();
    ?><li>
    <a href="<?php the_permalink()?>"><?php the_title()?></a><?php the_excerpt()?><?php the_date()?></li>
    <?php endwhile ?>
    <?php else : ?>
    <?php endif ?>
    
    </ul>
    
    </div>

    Use the template tag, the_time(), instead of the_date().

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Recent Posts with Excerpt’ is closed to new replies.