WordPress.org

Ready to get started?Download WordPress

Forums

Display only subcategories of one category (16 posts)

  1. shirasade
    Member
    Posted 9 years ago #

    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!

  2. Anonymous
    Unregistered
    Posted 9 years ago #

    What's a "rec"?

  3. TechGnome
    Moderator
    Posted 9 years ago #

    Rec = "recreational" .... I think.....
    TG

  4. lamb
    Member
    Posted 9 years ago #

    HmMm.. yah i would love that too..

  5. shirasade
    Member
    Posted 9 years ago #

    Rec = recommendations... :)

  6. carthik
    Member
    Posted 9 years ago #

    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.

  7. shirasade
    Member
    Posted 9 years ago #

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

  8. carthik
    Member
    Posted 9 years ago #

    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...
    :)

  9. shirasade
    Member
    Posted 9 years ago #

    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! :)

  10. theuniek1
    Member
    Posted 9 years ago #

    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 :)

  11. paperlion
    Member
    Posted 9 years ago #

    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.

  12. Minna
    Member
    Posted 9 years ago #

    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.

  13. mofotronimus
    Member
    Posted 9 years ago #

    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

  14. Minna
    Member
    Posted 9 years ago #

    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 :D 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

  15. Lorelle
    Member
    Posted 9 years ago #

    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.

  16. sithicus
    Member
    Posted 7 years ago #

    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?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.