WordPress.org

Support

Support » How-To and Troubleshooting » List main category, and only 1 level of sub categories

List main category, and only 1 level of sub categories

  • I’ve been looking around for how to do this, and there seems to be a ton of example on parents and children, but I can’t find one that does what I need.

    So, I have categories like…

    Food
    –Videos
    –Restaurants
    –Recipes
    —-Mexican
    —-Italian
    —-America
    Fashion
    –Style
    –Beauty
    —-Hair
    —-Makup
    –Clothing

    If the user is on a top level category page (such as /category/food/) OR if the user is on a sub page (either category/food/recipes/italian or just /category/food/recipes/), then I need to…

      Print the parent category name and link to it.
      List only the first level sub categories.

    So, if the user was on any food page (or sub category page), they would see the menu…

    [link to food page]Food[/]
    Videos
    Restaurants
    Recipes

    See below for where I am at… not really working and I’m sure my code needs to be cleaned up alot … So far, if I go to the top level page (i.e. /food/), it prints the ENTIRE list of categories and children. On the subcategory pages (i.e. /food/recipes/ or food/recipes/mexican/) it doesn’t show anything.

    [code moderated – please use the pastebin]

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘List main category, and only 1 level of sub categories’ is closed to new replies.
Skip to toolbar