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.
Any help is appreciated.
- The topic ‘Single.php w/ Show X number of posts from same category in side bar’ is closed to new replies.