Hello i need a code to display latest posts of a specific category on the sidebar of a wordpress blog. please help
I have seen several widgets like this that will show post from all categories. I am sure you could tweak the code to show just one category.
Have you tried this? James Lao's Category Posts Widget I don't know of one template tag that will do that, so you will probably need to add a block of code to the sidebar, like this: <ul> <?php $catposts = get_posts('numberposts=NUMPOSTS&category_name=CATEGORY'); foreach($catposts as $post) : ?> <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> <?php endforeach; ?> </ul> Code (markup): Change NUMPOSTS to the number of posts to list (eg. numberposts=5). It will get the latest posts by default. Change CATEGORY to the category stub text (eg. category_name=wordpress). If you want to use a category number, change category_name to category (eg. category=2)
THANK YOU. Even if the original writer never responds -- this is EXACTLY what I needed. I, too, had tried widgets, and they weren't working in my particular scenario. This is perfect. Thanks Cash Nebula.
Now there is an exciting piece of code. I did not know that function existed and queried the database the "old fashioned way" [direct php/sql] to get the same results. Thanks. Q...
Try this in the above code 15 is the number of posts and 6 are the category numbers . Replace it with ur own and if u want to include multiple categories in the side bar just add cat num followed by comma ( for ex : 6,7,8)