Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

    share|improve this question
    add comment

    2 Answers 2

    up vote 3 down vote accepted

    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.

    share|improve this answer
        
    this is what I was looking for, thanks a lot Stephen –  andresmijares25 Jan 16 '12 at 0:52
    add comment

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

    share|improve this answer
    add comment

    Your Answer

     
    discard

    By posting your answer, you agree to the privacy policy and terms of service.

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