Often there will be a category that needs to be called on specifically in your WordPress theme. If you don't know the category's ID, you can use the category name to retrieve the correct posts.
First, open the template file that you wish to insert the category Loop into. If you want to highlight a certain category in your theme's sidebar, for example, you would open sidebar.php
. Insert your cursor at the appropriate spot, and then add the following code:
<?php $cat_name = 'My Category Name'; query_posts(array('category_name'=>$cat_name)); if(have_posts() ) { while(have_posts() ) { the_post(); } } ?>
The available parameters for the query_posts
function are varied and many. In this instance, you take advantage of the category_name
parameter to ensure that only posts in the specified category (in this instance, My Category Name)
are returned for the Loop. Want to use a different category? Change the value...