WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Hide / Exclude Categories From Posts Page (11 posts)

  1. Natasha McEachron
    Member
    Posted 1 year ago #

    I have my blog setup with a static homepage and the blog index displays on a page called "blog" (http://nnmportfolio.com/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

    <?php
    $cat_to_exclude = 35;
    query_posts($query_string . '&cat=-'.$cat_to_exclude');
    ?>

    Code #3

    <?php if (in_category('35')) continue; ?>
  2. Ankush
    Member
    Posted 1 year ago #

    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]

  3. Natasha McEachron
    Member
    Posted 1 year ago #

    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: nnmportfolio.com
    My Blog Page: nnmportfolio.com/blog

  4. Natasha McEachron
    Member
    Posted 1 year ago #

    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:

    http://www.locoed.com/web-design/how-to-exclude-category-posts-wordpress-tutorial-code/

  5. Ankush
    Member
    Posted 1 year ago #

    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]

  6. Natasha McEachron
    Member
    Posted 1 year ago #

    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:

    http://www.locoed.com/web-design/how-to-exclude-category-posts-wordpress-tutorial-code/

  7. R Bouten
    Member
    Posted 1 year ago #

    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?

  8. R Bouten
    Member
    Posted 1 year ago #

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

  9. Natasha McEachron
    Member
    Posted 1 year ago #

    @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?

  10. R Bouten
    Member
    Posted 1 year ago #

    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.

  11. amberm
    Member
    Posted 1 year ago #

    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:
    <?php

    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?
    Thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic