Support » Fixing WordPress » Hide / Exclude Categories From Posts Page

  • Resolved Natasha McEachron


    I have my blog setup with a static homepage and the blog index displays on a page called “blog” ( I have a category called “photography” for which I recently created a separate website. As a result, I’d like to hide the photography category and its posts from the category list and blog pages but I don’t want to delete or prevent access to posts.

    Given that’s its only one category I would prefer to use code rather than a plugin. I tried searching the forums and elsewhere online but the instructions and codes that I found (see below) didn’t work and I don’t have much knowledge of PHP. I’d greatly appreciate any suggestions. Thanks!

    Code #1

    <?php if (is_front_page() && !is_paged() )
    $posts = query_posts($query_string . '&cat=-35'); ?>

    Code #2

    $cat_to_exclude = 35;
    query_posts($query_string . '&cat=-'.$cat_to_exclude');

    Code #3

    <?php if (in_category('35')) continue; ?>

Viewing 10 replies - 1 through 10 (of 10 total)
  • Read the entire article which solves the above two problems. I have read it over and over – many people on the forums are looking for a way to exclude posts or categories from their homepage.

    Also, some might be interested in creating a blog within your existing wordpress installation. If so, check this out for easy and fast solution.

    [Link removed]

    Hello Ankush,

    Thanks for replying. However, the Simply Exclude plugin won’t work for my needs because my blog posts are not displayed on the home page. The front page displays a static home page and the posts page is shown on a page called “blog”. I need to exclude the category from the category list and exclude its posts from the post pages.

    My Home Page:
    My Blog Page:

    I was able to find a solution for excluding the category from my blog post page. The instructions and code can be found at this link:

    Yes, my solution is basically geared towards people who have blog posts on front page.

    But there is a way around to solve your problem too. Its very simple if you think about it.

    Just create a category called “blogposts” – now have that category exclude from page, and create a new page with that category as linked.

    You have effectively created a system, so which all the articles posted in the “blogposts” category automatically go into your BLOG page.
    I have explained how to accomplish this in my article.

    [Link removed]

    Thanks Ankush but I was able to find a solution which fit my exact needs and only required a little bit of code. It was able to hide the category from both the sidebar and the blog posts page. Here’s the link:

    I was just working on this as well, but when I exclude a category if changes the post order from oldest to newest. Any clues?

    Interesting, it influences the order in my news feed but not order in the the category page.

    @r Bouten

    I changed my code and while it hid the category on my blog, all of the posts are still visible in my feed. I’m not sure of what might have caused the change in the order of your feed’s posts. Maybe you accidentally added or deleted a bit of code which affected the order?

    I haven’t had time to figure it out yet. But I read in an other thread someone with a similar problem found the solution in updating the MySQL version.

    I tried to use this code in WP 3.5 and get the following error code:

    Parse error: syntax error, unexpected T_NS_SEPARATOR, expecting T_STRING in /home/content/89/10409789/html/wp-content/themes/simple-catch-child/functions.php on line 8

    Here’s a copy of the code:

    function exclude_category($query) {
    if ( $query->is_home || $query->is_archive) {
    $query->set(‘cat’, ‘-4’);
    return $query;
    add_filter(‘pre_get_posts’, ‘exclude_category’);


    I don’t know PHP, I was just following the advice given. Can anyone tell me what the error code means?

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Hide / Exclude Categories From Posts Page’ is closed to new replies.