• OK, I’d SWEAR I’d seen this, but now I can’t find it. When on a page or viewing a category, is there a way to know if there are sub cats/pages under the current one? If I call wp_list_cats or wp_list_pages and set the child_of parameter and there aren’t any children, I get the dreaded “Warning: Invalid argument supplied for foreach() in…” error. Soooo, I want to know if it’s possible to know if there are children….

    I’d swear I saw a set of functions like “has_child” or something like that…. but can’t find it… and the searches don’t return any results. So I’m left to wonder if I’m crazy or not.

    Tg

Viewing 4 replies - 1 through 4 (of 4 total)
  • This should list children of the current category (that is, when on a category page):

    <?php wp_list_cats("child_of=$cat"); ?>

    Thread Starter TechGnome

    (@techgnome)

    *sigh* I know that…. but then that ALL I get…. just the children.

    Let me try to demonstrate. Currently I have this structure:
    # General
    * Site Updates
    * Friday Five
    * Rants / Soapboxes
    * Baby Watch ‘04
    # Writings / Scribblings
    * Thorak’s Tome
    * Poems
    * Keavar History
    * Short Stories
    * Rogue Redemption
    * Writing Notes
    # Humor
    # Uber Geekdom

    I’ve got afew top level cats, some of which have sub cats. I no longer want to display it like that. When on the main page, I want to display this:
    # General
    # Writings / Scribblings
    # Humor
    # Uber Geekdom

    Then when the user click on a cat that has sub cats, say “General” then I want this to be displayed when the page reloads:
    # General
    * Site Updates
    * Friday Five
    * Rants / Soapboxes
    * Baby Watch ‘04
    # Writings / Scribblings
    # Humor
    # Uber Geekdom

    And so on…. if I use child_of=1 (the General ID) I get this:
    * Site Updates
    * Friday Five
    * Rants / Soapboxes
    * Baby Watch ‘04

    NOT what I want. I’ve since come to realize that it’s not going to be possible this way. Soooooo I want to compromize. Leave the sidemenu as the default, showing only the top cats:
    # General
    # Writings / Scribblings
    # Humor
    # Uber Geekdom
    Then to have a horizontal menu at the top that lists the sub cats
    * Site Updates * Friday Five * Rants / Soapboxes * Baby Watch ‘04

    So I used the wp_list_cats(“child_of=”.$cat); function call…..
    And it works when I click on General or Writings/Scribblings…. but if I click Humor, which does not have any sub categories, I get the foreach error.

    Which is why I wanted to find out if there was a has_child function that would tell me if the current category (presumably I’d pass in the cat ID) has child categories or not. Then based on that, I could determine if I need to call the wp_list_cats or not.

    Hope that helps to clear things up a bit.

    Tg

    You might use set_error_handler(…) to override the standard error handling. Just a thought.

    Thread Starter TechGnome

    (@techgnome)

    Still seems like a propblem to me. I’d just assume not mess w/ the error handler as I’m not sure I’d be able to reset it back once done. And for something as simple as this, that seems pretty heavy handed.

    Maybe the solution is for me to simply roll out my own function that does what I need it to do.

    hmmm….. there’s a thought forming…..

    Tg

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Is there Sub Cats/Page?’ is closed to new replies.