Support » Themes and Templates » Showing Posts from that category only

  • Hi

    I am sure this is very simple but I can’t work it out. What code do I use to show post from only that category please? I would like to post the code in the sidebar as archives.

    Many thanks.


Viewing 5 replies - 1 through 5 (of 5 total)
  • I’m sure there are other ways to do this, but I use Scott Reilly’s Customizable Post Listing plugin:

    After installing the plugin (instructions on the web site), you’ve got a new function that you can drop onto the sidebar to show recent posts in a specific category, which I think is what you’re asking for.

    I’ve found it stable and very flexible — but from the Worpress 2.1 compatibility list, a different solution is needed for 2.1 based systems.


    Thanks for the tip for the plugin. It works and it works well. However, I am having a slight problem in that I have created a template for the category ‘heritage’. That template using the plugin to display a link to the rest of the heritage posts. See:
    Heritage Page. However, when I click on a link it reverts back to the index.php template. Is this something wrong with my template? I thought that when you created a template called ‘category_8.php’, all posts relating to that category would revert to that template. Do I need to create a single post template for that category as well please?



    I don’t claim to be an expert in the template hierarchy, but the “category_*.php” is used when displaying a category, i.e. the page that you get when the URL is something like


    When you click a link from the list of articles in the category, that takes you to a post which will be displayed in the format defined by single.php (if it exists) or index.php (if there’s no single.php). So, yes, that’s where you’ll need to make a change.

    In the page describing the template tag in_category there’s an example of customizing the single.php based on the category ID.

    Or you might look at Customizing your sidebar page from the Codex, where there’s a reference to a “related articles” plugin.

    Best wishes.

    First of all it should be category-X.php and NOT category_X.php (dash, not underscore!)

    As converting2wp pointed out Category Templates are used by WP to display the so-called category archives.

    And yes, you need a “post template” in order to have different display for single posts in a certain category.
    However, WP doesn’t have that feature out of the box, so you need a plugin:
    (there is another plugin mentioned there, too)

    Thanks for the correction and the pointer to the plugin!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Showing Posts from that category only’ is closed to new replies.