Tech

Showcase Recent Posts from One Category

I wanted a way to be able to showcase my latest Recipes & Techie Tip posts on the sidebar of my blog for easy reference for my visitors (yes, you guys!) seperating them from the Recent Posts and Archives. So I found a way of using the coding for Recent Posts and adapting it to showcase a specified category ultimately highlighting a set amount of posts, in my case, 5.

The coding for this is as follows:

[cc][/cc]

Within this code, the “query_posts code” tells WordPress to find the latest set amount of posts within the specified categories, I chose 5 & then runs the code in a loop to display them.

I have then added CSS to stylize the displayed posts using little arrows so it looks nicer than just plain text. The CSS code is within my style.css file and called for within the php code with DIV & LI tags.

[cc]#food {
list-style:none;
margin-bottom:7px;
padding-left:15px;
background:url(arrow1.gif) no-repeat left center;
border-bottom:1px dashed #cdcdcd;
}
[/cc]

This is a handy piece of coding for you to use if you want to showcase posts from several categories like I have. So try it out & let me know what you think!

Note: If you are using widget sidebars, you will need to install the Exec-PHP plugin, then add the code to a text widget, otherwise this will not work. The Exec-PHP let’s you add PHP coding within posts, pages and widgetized sidebars.