wordpress - display posts according to categories

Most Wordpress themes come with this feature - Recent Posts - included automatically but if you prefer to display recent posts depending by category you have to some simple modifications.

In case the theme chosen by you has already this feature you must find her, usually in sidebar.php and looks like this:

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

Before you make these changes i suggest to backup sidebar.php to avoid any inconveniences in case something goes wrong. After you found that code all you need to do is to change the code with next one:

<?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(); ?>
<?php endwhile; ?>

Where say cat = 1 must enter the number assigned to the category for which you want to display recent posts. This number can be found in: Manage - Categories page.
To set how many items to display modify here: showposts = 10, where 10 is the number of items you want to display it.
It is quite simple and I do not think you have problems with implementation.

Place a link to your site with refference to this article,if you want to use this post!!

Link To This Post
1. Click inside the codebox
2. Right-Click then Copy
3. Paste the HTML code into your webpage
  • Share/Save/Bookmark

Related posts:

  1. Wordpress Optimization: permalinks, titles and metatags
  2. SEO Plugins Wordpress
  3. WordPress Optimization for search engines

Leave a Reply