• I would like to display a specific category and that category’s children. I can’t get the children to display.

    wp_list_categories(
    	'include'		=> $cat_id,
    	'depth'		=> 0,
    	'hide_empty'	=> 0
    
    );

    What am I doing wrong? Only the parent category is showing up.

Viewing 8 replies - 1 through 8 (of 8 total)
  • esmi

    (@esmi)

    Have a look at the child_of parameter.

    Thread Starter Sebastien Couture

    (@scouture)

    I tried the child_of parameter but I would also like to show the parent category.

    I thought my above function parameters would word as I am using depth = 0 which is suppose to show “All Categories and child Categories”.

    esmi

    (@esmi)

    You’re using the include parameter in your function – which means that only the post in that specific category will be listed.

    jocken

    (@jocken)

    Thread Starter Sebastien Couture

    (@scouture)

    I think I may have been unclear because what I’m trying to do seems so simple. Then again I could be wrong.

    I want to input a category ID into the function and get the following output.

    <ul>
    	<li><a>Parent category</a></li>
    	<ul>
    		<li><a>Child category 1</a></li>
    		<li><a>Child category 2</a></li>
    		<li><a>Child category 3</a></li>
    	</ul>
    </ul>

    I would like to know if there is a way to do this with wp_list_categories or if I will need to write a custom function to include the category IDs I want.

    esmi

    (@esmi)

    You’d need to create a custom function or code block that uses wp_list_categories with the child_of parameter.

    Thread Starter Sebastien Couture

    (@scouture)

    Ok,

    Ended up doing this

    <?php $categoryParentArgs =	array(
    	'title_li'			=> '',
    	'include'			=> $catID
    ); ?>
    <?php $categoryListArgs =	array(
    	'title_li'			=> '',
    	'child_of'			=>$catID
    ); ?>
    <ul>
    <?php wp_list_categories($categoryParentArgs); ?>
    <?php wp_list_categories($categoryListArgs); ?>
    </ul>

    Hey Sebastien,

    How did you wind up implementing this? I’m attempting to use your code, and I want multiple lists of categories with their parent, just like you said. However, I’m not sure how to define each lists’ parent using your $catID?

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘wp_list_categories => list parent and children’ is closed to new replies.