I'm trying to create a menu directly hard-coded, basically I need to display the parent category and below its child categories, however I have to do this several times meaning something like this:

    Category 1

  • category child of 1.1
  • category child of 1.2
  • category child of 1.3
    • Category 2

  • category child of 2.1
  • category child of 2.2
  • and so on....

    I've tried whit different kinds functions like call the category and is subcategory to call its ancestor, however I haven't been able to get the result I'm looking for.

    Any suggestion??? Thanks in Advanced.


    Have you tried

    wp_list_categories( array('depth'=>2,'title_li'=>null));

    This outputs the categories as a list, with their children as a nested list. The categories are linked to their respective page.

    • this is what I was looking for, thanks a lot Stephen – andresmijares Jan 16 '12 at 0:52

    use get_categories() with the 'parent' parameter to get only top level categories; the use a foreach loop to loop through these categories, and use the 'parent' parameter or the 'child_of' parameter. depending on your formatting requiements, this might also work with wp_list_categories()

    Your Answer

    By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

    Not the answer you're looking for? Browse other questions tagged or ask your own question.