WordPress.org

Forums

Single.php w/ Show X number of posts from same category in side bar (1 post)

  1. cent
    Member
    Posted 8 years ago #

    Hi.

    On single.php, I would like to show in the sidebar all or X number of posts from the same category in the side bar.

    So if you're viewing Post 1 which is in XHTML (cat), then the sidebar should show say 10 of the last posts (ordered by date desc) from the XHTML category.

    If you're viewing Post 2 which is in News (cat) AND Technology (cat), then the sidebar should show say 10 of the last posts (ordered by date desc) from the News and Technology categories.

    I've seen this code before:

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

    However, I can't seem to find a way to get the category ID to insert into it. Also, if this single post is in multiple categories, I don't know how to indicate that in the query string.

    I've seen the Customize Post Listing at . But it seems like you have to supply a single Cat ID, whereas there may be multiple ones.

    Any help is appreciated.

    Thanks
    Cent

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.