Reputation: 195
I'm trying to make a theme which shows an overview of child categories with title, link and description when entering a category archive. However, I only want to show child categories one level below the current category, and not the children of child categories.
How do I do that?
<?php
global $ancestor;
$childcats = get_categories('child_of=' . $cat . '&hide_empty=1');
foreach ($childcats as $childcat) {
if (cat_is_ancestor_of($ancestor, $childcat->cat_ID) == false){
echo '<li><h2><a href="'.get_category_link($childcat->cat_ID).'">';
echo $childcat->cat_name . '</a></h2>';
echo '<p>'.$childcat->category_description.'</p>';
echo '</li>';
$ancestor = $childcat->cat_ID;
}
}
?>
I found that code, but it only returns one child. It returns. (Faa and Faq are child categories)
Thanks!
Upvotes: 0
Views: 1368
Reputation: 5903
Make sure 'FAQ' has post under it. If you notice the "code you found" is passing the parameter "&hide_empty=1" which means it will not return categories that are empty.
So your options are to either remove that or make sure your category has posts under it.
Upvotes: 1