Support » Fixing WordPress » Display only subcategories of one category

  • I just created my first WP-run site, to run a rec page with it. I’m using a nightly of 1.2, because I need the subcategory function. Now I’ve been looking for a solution of my biggest problem so far: People need to be able to navigate from main category to subcategory, in order to find exactly the recs they’re looking for.
    Using this bit of coding
    < ?php list_cats(0, ‘All’, ‘name’,”,”,TRUE, FALSE, FALSE, FALSE, FALSE, TRUE); ? >
    I can display the complete tree of categories and subcategories – but now I’d love to choose one category and display only the tree beneath it. Just thought I’d ask here if someone knew how to do that, because I know nothing about php and can’t write my own code.
    Also, sorry about probably messing up the code, but I don’t know what ‘backticks’ are. As I said – total newbie… Thanks for any help!

Viewing 15 replies - 1 through 15 (of 15 total)
  • What’s a “rec”?

    Rec = “recreational” …. I think…..
    TG

    HmMm.. yah i would love that too..

    Rec = recommendations… 🙂

    Dougal has added the parameter $exclude to the the function now. You should be able to get that new function with the latest version/build.

    Great, I’ve upgrated right away! So, how to I implement that new function now? I’m sorry, but I’m truly clueless…

    wp_list_cats('exclude=1,2,3');
    if you want to exclude the categories with id 1, 2 and 3.
    if you want to exclude only category with id 4, use
    wp_list_cats('exclude=4');
    If you are using permalinks, you can still find the category id from the admin interface…just hover your mouse pointer over the category names in the edit category interface, and you will be able to see the ?cat=XX in the status bar…
    🙂

    Thank you! I do hope I only have to exclude the top-level categories, else it’ll take me a while to get all the different IDs for the subcategories (took me forever to create the hard-coded drop-down menus I’m using at the moment)… But thanks a lot for your help, I’m sure I can manage this! 🙂

    theuniek1

    (@theuniek1)

    It’s in the WP wiki – you can display the subcategories using:
    wp_list_cats(‘child_of=#’)
    where #=main category # (not child category #)
    This will display only the children of the specified category, but not the main category itself.
    Hope this helps someone out 🙂

    I can’t seem to find this ref in the Wiki. Anyone know where it is.

    This is almost exactly what I’m looking for. I put some foreign language posts in their own category and want to keep them from displaying except in their own segregated pages.

    thanks.

    here’s the wp_list_cats tag
    but if you want to hide a category from the main page etc. that’s not going to help. See Kitten’s Show Categories plugin (that’s an old link but the plugin can be downloaded there, I haven’t figured out the repository yet).

    Template Tags, that’s the place to go looking for, er, template tags.

    hello, I’m a complete moron when it comes to this jargon. I think i’m looking to do what everyone else here is: list subcategories underneath main categories…

    It seems like there’ s a solution here, but i’m still unsure how to implement it. could anyone explain how- where to put it, so that someone as clueless as me can understand it?

    – thanks much

    If a (sub)category doesn’t have posts, it won’t show up. If that’s your problem (and it’s still a current issue), you can get the “effect” by using the argument ‘hide_empty=0’: <?php wp_list_cats('hide_empty=0'); ?> or, if there already are other arguments inside brackets, you can add it at the end as &hide_empty=0 so that all arguments (something=something) are inside one pair of single quotes.
    And you can put it wherever you want 😀 Most likely in a sidebar. So, if you are using 1.5 it should/could be in sidebar.php file, or for 1.2.x in index.php wherever the div IDed menu or sidebar is

    But has anyone solved the issue of getting the children of categories to only show up when visiting that category while the rest of the children stay hidden?

    I see it asked all the time on the forum and I’ve been waiting for an answer.

    sithicus

    (@sithicus)

    It’s in the WP wiki – you can display the subcategories using:
    wp_list_cats(‘child_of=#’)
    where #=main category # (not child category #)
    This will display only the children of the specified category, but not the main category itself.

    In response to this:

    Is there a way to auto detect what category it is in so we don’t need to create x number of category pages? X being the number of categories?

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Display only subcategories of one category’ is closed to new replies.