How to list previous posts on side bar? (3 posts)

  1. racheld
    Posted 10 years ago #

    I'm really new to this all, but have experience in website designing, but just learning how to edit php.

    I've noticed on other blogs that there is a section on the sidebar that lists "x" amount of previous posts. That way visitors can see the titles of your last 10 or so posts, click on one, and read it.

    How do you add this feature?



  2. Michael Bishop

    Posted 10 years ago #

    Generally speaking, this is how I achieve recent posts.

    <h2>Recent Posts</h2>
    $posts = get_posts('numberposts=5');
    foreach($posts as $post) :
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php endforeach; ?>

    Where as numberposts is obviously the number you want. You can also add the_content, or the_excerpt if you'd like.
    Conversely, I'm sure there are a few plugins that achieve this, I just haven't used them.

  3. racheld
    Posted 10 years ago #

    Thank you! I'll give that a try and also look into some plugins!

Topic Closed

This topic has been closed to new replies.

About this Topic