WordPress.org

Ready to get started?Download WordPress

Forums

Widget that provides recent posts from a category? (4 posts)

  1. bryan868
    Member
    Posted 7 years ago #

    How hard would it be to write a widget that provided the 5 latest posts from a particular category? Does anyone know of a widget like this that's already out there?

  2. drmike
    Member
    Posted 7 years ago #

    Look at one of the latest posts widget and replace the line containing the template call for the latest posts with one calling the latest posts for the specific category.

    You'd have to rename the functions as well so they don't be duped.

    Shouldn't be too hard.

  3. livemtl
    Member
    Posted 6 years ago #

  4. lloydarmbrust
    Member
    Posted 6 years ago #

    Well, I already answered this in another post, but here it is again:

    <ul>
     <?php
     global $post;
     $myposts = get_posts('numberposts=5&offset=1&category=1');
     foreach($myposts as $post) :
     setup_postdata($post);
     ?>
        <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
     <?php endforeach; ?>
     </ul>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.