I'm displaying sub-categories on the Categories page - similar to the way contents are displayed on WordPress Codex pages. I'm using blocks with predefined heights to display individual posts within the categories page and floating the "sub-category list" with them. If I don't specify the height of the list, the boxes are not aligned.
- I need to specify the height of the "sub-category list".
- A default height is defined in the stylesheet.
- To dynamically adjust the height of the list, I'm using inline styling.
- To define the height of the list using inline styling (to a pre-defined value), I need to first determine the number of sub-categories in the list (prior to executing wp_list_categories).
Before, this is what I used and it worked like a champ:
$currentcat=get_query_var('cat');
$categories= get_categories('child_of='.$currentcat.'&depth=1');
$catcount = count($categories);
$catcount was used to determine the height then specify it with inline styling. Then inside the div I ran:
foreach ($categories as $cat) {
$catlist = '<li><a href="'.$cat->category_nicename.'">';
$catlist .= $cat->cat_name;
$catlist .= '</a></li>';
echo $catlist;
}
Now I want to exclude child categories - I only want to go 1 level deep with sub-categories in the list.
So I need to do one of two things from what I can tell:
- Count the number of results from wp_list_categories prior to executing it.
- Count the number of results (only 1 level deep) using get_categories.
OR
Here's the wp_list_categories I'm running:
wp_list_categories ('title_li=&child_of='.$currentcat.'&depth=1&show_count=1');
Any suggestions would be appreciated.