Forums

[resolved] wp_list_categories() post and link categories - WHY? (11 posts)

  1. poodlerat
    Member
    Posted 5 years ago #

    I've upgraded to 2.1 and changed

    wp_list_cats('sort_column=name&hide_empty=0&exclude=1')

    to

    wp_list_categories('orderby=name&hide_empty=0&exclude=1&title_li')

    in my sidebar.

    I have no posts in any of my link categories, and no links in any of my post categories, but my link categories are being displayed in the list along with my post categories. How do I get rid of them?

  2. MichaelH
    Volunteer
    Posted 5 years ago #

    Might not be what you want but by deleting the &hide_empty parameter, it will stop showing the categories you've got associated with links.

  3. poodlerat
    Member
    Posted 5 years ago #

    Thanks, but I can't do that, because my post categories are organized within empty parent categories. If I hide the empty categories, none of my categories will show.

    I've sort of fixed it by excluding all the link categories, but it's not a permanent solution - I shouldn't have to go back and change my template every time I want to add a new link category.

  4. Otto
    Tech Ninja
    Posted 5 years ago #

    Try adding "type=post" to your query string. See if it helps.

    Or you could put your Link Categories under a single parent, and then exclude that parent.

  5. MichaelH
    Volunteer
    Posted 5 years ago #

    Unless you do the exclude, such as you and Otto42 suggested, given the current wp_categories structure, I guess you can't always know that a given Category is a post category or a link category.

    It seems if there is a non-zero value in the category_count field, that Category is considered a post category, and if link_count has a non-zero value it is considered a link category. But if both fields are zero then what kind of Category is it?

  6. Otto
    Tech Ninja
    Posted 5 years ago #

    Near as I can tell, it's both until such time as you put a post under it or put a link under it. I dunno, that bit is slightly confusing.

  7. poodlerat
    Member
    Posted 5 years ago #

    "type=post" did absolutely nothing, and when I checked the wp_list_categories page in the codex, it wasn't listed as one of the possible paramters, so I'm kind of confused about it.

    But I tried deleting the hide_empty parameter, just to see what would happen. I thought it would behave as I described above, but it didn't - all my post categories are showing up, even the empty parent ones and all their children. Which is very, very weird - the fact that empty parent cats wouldn't show up (even if their child cats weren't empty) prior to 2.1 was the reason I had it set to hide_empty=0 in the first place. In terms of template tag behaviour, the jump between 2.0 and 2.1 has been bigger than between 1.5 and 2.0, which is unexpected.

    Anyway, thanks for your help!

  8. Otto
    Tech Ninja
    Posted 5 years ago #

    type=post/link is not in the codex yet. 2.1 is too new for all the codex changes to have been made.

  9. MichaelH
    Volunteer
    Posted 5 years ago #

    @Otto42:

    Am I missing something? I'm not seeing that 'type=' parameter in category-template.php.

  10. Otto
    Tech Ninja
    Posted 5 years ago #

    Yep. Notice how it passes along the args to get_categories() in the form of an array? Might check the params for get_categories() as well.

  11. MichaelH
    Volunteer
    Posted 5 years ago #

    Cool. And I see R. Boren suggested get_categories in a wp-testers thread:

    Or get_categories('type=link')

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.