Support » Plugin: List category posts » Excluding category not workin

Viewing 6 replies - 1 through 6 (of 6 total)
  • The syntax is correct, however the categorypage and id settings (and name setting) can not be used together.

    The code goes: if categorypage … elseif name … elseif id

    You would need to use the name or id if the post is in more than one category and you only want the first category.

    Thank you for your help. So that I do not misunderstand your advice, could you please give me an example using my syntax: [catlist categorypage=”yes” id=-10] In other words, can I get this to work by changing the syntax or is what I am trying to achieve not possible? (my reading is that you are saying that it is not possible)


    That is correct, it is not possible to do it that way. You would have to use the id of the category you want (or the name with a mod) instead of categorypage.

    i.e. you want posts in category id 9 but not posts also in category 10:

    [catlist id=9,-10]

    Alternatively, there is a modification you can make to use the name setting instead. I’ve posted the updated changes here.

    i.e you want posts in category-a but not posts also in category-b:

    [catlist name=category-a,-category-b]

    Sorry, don’t do that, let me correct myself.

    You would only need to use the id of the category you want, not the id of the category you don’t want. Specifying the id of the category you do not want would cause it to not display posts that are in BOTH categories).

    This is all you need:

    // post's first category id is 9
    [catlist id=9]

    On another note…

    I have not fully tested the following code, but it should work. If you are comfortable with editing the theme code, you can do something similar in the loop in single.php (or other desired template). This way you would not need to know the category id, but it would display a catlist on all posts (unless you add some conditionals).

    This code would get the categories that a post is in and only display the catlist for the first category

    $theCategories = get_the_category();
    $category1 = $theCategories[0]->term_id;
    echo do_shortcode("[catlist id=$category1]");

    Like my first code examples, this code will do the same, and excludes posts that are also in the other categories.

    $theCategories = get_the_category();
    $category1 = $theCategories[0]->term_id;
    if(isset($theCategories[1])) $category2 = $theCategories[1]->term_id;
    if(isset($theCategories[2])) $category3 = $theCategories[2]->term_id;
    echo do_shortcode("[catlist id=$category1,-$category2,-$category3...]");

    Make sure those last two codes blocks are used inside the loop.

    Thanks very much for the advice. I will try this.


    Basically, if a post is in more than one category but you only want to display posts from one of those categories, you have to specify the id of the desired category.

    [catlist id=9]

    The rest just gives you more advanced options.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Excluding category not workin’ is closed to new replies.