How To: Display the Recent Posts of Specific Categories

Most WordPress themes, by default, come with Recent Posts displayed automatically. Depending on the type of blog you run, it is possible that you would prefer to display Recent Posts per category. If this is the case, here is what you need to do to only display recent posts for specific categories.

First, you’ll want to find your Recent Posts code, which is usually found in the sidebar. It will look something like this:

<h2>Recent Posts</h2>
<ul>
<?php get_archives('postbypost', 10); ?>
</ul>

As always, make sure you have a backup of the file in question before making any changes. You’ll then want to replace the above code with the following code:

<ul>
<?php $recent = new WP_Query("cat=1&showposts=10"); while($recent->have_posts()) : $recent->the_post();?>
<li><a href="<?php the_permalink() ?>" rel="bookmark">
<?php the_title(); ?>
</a></li>
<?php endwhile; ?>
</ul>

Where is says cat=1, you’ll want to insert the number assigned to the category that you want to display the posts from. You can find this from your Manage -> Categories page. You can also adjust the number of posts to be displayed where it says showposts=10.

This could be useful to someone who wants to display the most recent few posts from a few different categories in their sidebar.

[via ReadyWPThemes]

  • Leave a Comment
  • Turn WordPress Into A CMS With WordPress Plugins

    With the recent popularity of themes attempting to turn WordPress into a content management system (CMS), people have begun purchasing premium WordPress themes in order to get the features and look they are wanting for their website.

    As Josh Byer’s points out, people can instead use free WordPress plugins to achieve much of the CMS functionality they are looking for.  Miriam of WordPress Garage also adds that a few additional plugins to turn WordPress into a CMS.  

    While using a theme designed specifically to function as a CMS has a few advantages, I think those of us that are on a budget can definitely get many of the CMS features we crave through the use of these WordPress plugins.

    If you were looking to purchase/download a CMS, what options are you most looking for?  Can you get this functionality via plugins?  I’d love to get everyones thoughts on this!

  • Leave a Comment
  • Tips For Highlighting Author Comments in WordPress

    In the past we’ve gone over some methods for setting up your theme to separate your author comments in WordPress. By default, most WordPress themes check the e-mail address to determine who the person is that is leaving the comment. By adjusting the code to check for the user id instead, you can set up your theme to recognize if you are the author of the post. This is also beneficial for blogs with multiple authors.

    In addition to separating trackbacks from comments, this is another way you can easily help improve the readers experience when trying to follow a conversation in the comments. Most people use a different background, but some choose to instead display a logo. The important thing is that readers can recognize which comments are coming from the author of the post.

    Today I noticed Matt Cutts has written his own tutorial explaining how to highlight author comments in WordPress. His post also includes the code needed for CSS styling. If you still haven’t gotten around to doing this on your theme yet, I recommend you check it out!

  • Leave a Comment