WordPress makes it possible to pull in very specific types of content on your Web site through the <query_posts> template tag. If you have a category called WordPress, and you want to display the last three posts from that category on your front page, in your blog sidebar, or somewhere else on your site, you can use this template tag.

The <query_posts> template tag has several parameters that let you display different types of content, such as posts in specific categories and content from specific pages/posts or dates in your blog archives. To see the many variables and parameters the <query_posts> tag lets you pass visit this page WordPress Codex.

To display specific content, you have to find the ID number for the category you want to use; then you have to tell WordPress how to display the content. The unique ID number for a category is not easy to find unless you know where to look. Follow these steps:

  1. Click the Categories link on the Posts menu.

    The Categories page opens.

  2. Hover your mouse over the name of the category that you need the ID number for.

  3. Look in the status bar of your browser to view the category ID number.

    Find the unique category ID number.
    Find the unique category ID number.

    When you have the category ID number in hand, you’re ready to add the <query_post> tag to your template.

    Here is an example of two parameters you can use with the <query_posts> tag:

    • showposts=X: This parameter tells WordPress how many posts you want to display. If you want to display only three posts, enter showposts=3.

    • cat=X: This parameter tells WordPress that you want to pull posts from the category with this specific ID number. If the ID category is 40, enter cat=40.

  4. Click the Editor link on the Appearance menu.

    The Edit Themes page opens.
    The Edit Themes page opens.
  5. Click the template in which you want to display the content.

    If you want to display content in a sidebar, for example, choose the Sidebar template: sidebar.php.

  6. Locate the ending </ul> tag at the bottom of the template for the theme you’re using.

    If you’re using the Twenty Ten theme, the ending </ul> tag is the second-to-the-last li
    If you’re using the Twenty Ten theme, the ending </ul> tag is the second-to-the-last line.
  7. Type the following code directly above the ending </ul> tag:

    <?php query_posts(‘showposts=3&cat=40’); ?>

    <h2>Type Your Desired Title Here</h2>

    <?php if (have_posts()) : while (have_posts()) : the_

    post(); ?>

    <strong><a href=”

    rel=”bookmark” title=”Permanent Link to

    the_title_attribute(); ?>”>


    <?php the_excerpt();endwhile;endif; ?>

    In the first line you can change the numbers to suit your specific needs. Just change 3 to whatever number of posts you’d like to display (there is no limit!), and change 40 to the specific category ID number that you want to use.

  8. Click the Update File button.

    The changes you just made are saved to the sidebar.php template.