ThemeShaper Forums » Power Blog

[closed]

exclude posts from specific categories

(12 posts)
  1. Hi,

    I'm trying to exclude posts from one category on the home page. I'm using WP3RC3 and this is what I tried. I am absolutely dumb with regards to PHP and programming in general.

    //Exclude posts from category xyz
    function excludeposts() {
       if (is_home()) {
          query_posts("cat=-4136");
       }
       }
    add_filter ('thematic_content','excludeposts');

    Thanks for the help --any help.

    Posted 4 years ago #
  2. Hi,

    try a different action hook :)

    //Exclude posts from category xyz
    function excludeposts() {
       if (is_home()) {
          query_posts("cat=-4136");
       }
       }
    add_filter ('thematic_above_indexloop','excludeposts');

    Chris

    Posted 4 years ago #
  3. Thank you very much! I can't say I understand why but I'm very happy that you've helped me out here!

    Posted 4 years ago #
  4. sober
    Member

    I presume 4136 is the category id. Isn't it so ?

    Posted 4 years ago #
  5. Hi Sober,

    Yes, that's right.

    Posted 4 years ago #
  6. Hi,

    I have been looking around to try and find a solution to this. I have multiple blogs using the same theme and want to keep the category name as generic as possible. Category ids across the network could change etc.

    //Exclude posts from category xyz
    function excludeposts() {
    $id = get_cat_id('insights');
    if (is_home()) {
    query_posts("cat=-$id");
    }
    }
    add_filter ('thematic_above_indexloop','excludeposts');

    This works but how would I add multiple named categories to the string $id?

    I tried using an array after get_cat_id(array('insights','cat2')); but this didn't work

    Cheers in advance

    Posted 4 years ago #
  7. Robo
    Member

    Brilliant Chris, but was this documented anywhere?

    Posted 3 years ago #
  8. I tried using this code on my blog feed to exclude the events category (I am using the event calendar plugin by Alix Tingle) . It works great on the blog page landing page, but on the subsequent "paged" pages, the category is not being excluded. Any insight would be appreciated!

    Here is my code:


    //Exclude posts from category xyz
    function excludeposts() {
    if (is_home() & !is_paged()) {
    $page = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts("cat=-3");
    }
    }
    add_filter ('thematic_above_indexloop','excludeposts');

    Posted 3 years ago #
  9. I've tried the original function from Chris above with edits to try and peel out "News" category from the Blog page.

    //Exclude posts from category xyz
    function excludeposts() {
       if (is_page('blog')) {
          query_posts("cat=-3");
       }
       }
    add_filter ('thematic_above_indexloop','excludeposts');

    But I see this hook is not in Thematic's page.php file, which I believe is running the blog page.

    Posted 3 years ago #
  10. I was looking for this too- excluding one or more categories from the blog page. A good simple answer is here: http://forums.themeshaper.com/topic/exclude-categories-from-posts-page

    Posted 3 years ago #
  11. I tried Chris' solution and it seemed to work until I noticed that when I click on the previous posts links the next page shows the same posts as on the home/index page.

    I exclude four categories (and want to show 10 posts) on the home page

    function excludeposts() {
    if (is_home()) {
    query_posts("cat=-12,-3,-13,-3846");
    }
    }
    add_filter ('thematic_above_indexloop','excludeposts');

    Posted 3 years ago #
  12. Never mind, I found the solution here: http://forums.themeshaper.com/topic/exclude-a-category-from-index-loop#post-20941

    Posted 3 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.