WordPress.org

Ready to get started?Download WordPress

Forums

List category posts
Excluding category not workin (7 posts)

  1. Harris_S
    Member
    Posted 1 year ago #

    Hi,
    I am trying to display all posts of the category associated with a posting but to exclude the second category but it does not appear to be working: [catlist categorypage="yes" id=-10]

    Is my syntax incorrect?
    Harris

    http://wordpress.org/extend/plugins/list-category-posts/

  2. Web2Guru
    Member
    Posted 1 year ago #

    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.

  3. Harris_S
    Member
    Posted 1 year ago #

    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)

    Thanks
    Harris

  4. Web2Guru
    Member
    Posted 1 year ago #

    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]
  5. Web2Guru
    Member
    Posted 1 year ago #

    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.

  6. Harris_S
    Member
    Posted 1 year ago #

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

    Harris

  7. Web2Guru
    Member
    Posted 1 year ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic