Hi,
New here and pretty new to WordPress theme coding, so apologies if this is obvious, posted in the wrong place, etc.
Here's what I need to do: find all of the categories that don't have any parents, and then list them with their children. I can't just run wp_list_categories because front-end issues require me to break things up into separate <div>s. (Actually, though, maybe this is my mistake, so I'll ask that, too, after the question I was planning to ask.)
So here's the code:
<?php
$args = array(
'hide_empty' => 0,
'order' => 'desc',
);
$categories = get_categories( $args );
$parents = array();
$j = 0;
for ($i = 0; $i < 20; $i++) {
if (empty($categories[$i]->category_parent)) {
$parents[$j] = $categories[$i]->cat_ID;
$j++;
}
}
?>
<div id="header-lower-1">
<?php $inc = (string) $parents[0]; ?>
<h2><?php wp_list_categories('include=$inc&title_li=&style=none'); ?></h2>
<?php wp_list_categories('child_of=$inc&title_li='); ?>
</div>
So what am I doing wrong? By experimenting with things I've determined that the code is finding 4 parentless categories, which is what it should be finding. And it seems to be storing values in the $parents array. But the last few lines just give me "no categories" twice on the page, even though I've got categories. What gives?
Second question: to avoid this whole mess, is there a way to format an unordered list into columns, with parent categories at the head of each column and child categories below? That's more CSS wizardry than I've been able to think up, but if someone could just give me the trick for that I'd be set, too.
Thanks!