Help & tips on searching help me
Advertising

Article written on 17/08/08
& last updated on 13/06/09.

Offsite links

Posts in same category

It seems like such a stupidly easy thing to want to do. When you look at a single article, display a list of other recent articles in the same category (section) on the side of the page.

Strangely it doesn’t seem to be that easy in reality, as the wordpress support forums have several posts asking how to achieve it.

There is a WordPress plugin that works very well and will do it for you, but sadly it doesn’t seem to work in WP2.6.

So, I decided to do it myself, and here is the code for anyone else wondering how to achieve it.

global $post;
$categories = get_the_category();
$category = $categories[0];
$cat_ID = $category->cat_ID;

$myposts = get_posts("numberposts=20&category=$cat_ID");
?>



Your turn - leave a comment

Required

Required