• I use categories (1, 2, 3, etc) and sub-categories (1-1, 1-2, 1-3, etc) to structure my posts into different sections of the website. I have a category called ‘Current projects’ where I post updates for ongoing projects. These ‘Current projects’ posts are also divided into the regular category system, such that a post for an ongoing project has the categories ‘Current projects’, 1, 1-1, and 1-3 for example.

    My problem is that uncompleted projects show up in the archives when someone views projects by category. Ideally, I would like to hide all posts that have been assigned the category ‘Current projects’ so that they are never shown except on a page for current projects. When they are completed I simply untick the Current projects category for that post and it is shown as normal. How do I do this?

Viewing 4 replies - 1 through 4 (of 4 total)
  • You’d have to modify an existing or create a new loop to use for displaying your categories. Within that you can use the category parameters to set up how you want the loop to act based on your category structure.

    Thread Starter Blaque

    (@blaque)

    Thanks, ninjagowoo, for that reply. As I am not very skilled at all in PHP programming, would you be able to provide me with some more details of how I would go about?

    You can exclude a certain category from the archives by adding a bit of code into the archive.php file of your theme right before the loop.

    For example, using TwentyEleven’s archive.php, I would change this:
    <?php if ( have_posts() ) : ?>

    to this:
    <?php if ( have_posts() ) : ?>
    <?php query_posts('cat=-3') ?>

    The id 3 refers to the category id you want to exclude.

    In category.php, add this instead:
    <?php if (!is_category('3')) { query_posts('cat=-3'); } ?>

    This excludes your Current Projects posts from every browsing category pages except the Current Projects category.

    For further reading, there is a lot of information in the codex about query_posts and conditional tags.

    There are two kind of helpful people here at the WP forum:

    1. the kind who are knowledgeable, so knowledgable that they simply refuse to point people to the solution but to provide links to a bunch of technical readings because they believe that no one should take the shortcut even if programming is not their profession.

    2. the kind who understand the frustration and the level of capability of those who don’t understand programming, and to provide concise solution or direction to resolve the issues.

    oliverchank is the #2. Thank you!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Multiple category posts – exclude certain category’ is closed to new replies.