I want to pass the id of the parent category to a for each loop. When I pass the result manually and fill this in, then the for each loop works. However when I pass the variable $qi to the for each loop, then I just get a result for the first ID? The relevant part of the code is marked with a comment.
I still have to the combine double ids', but I would like the for each loop to work first.
<?php
$categories = get_categories();
foreach ($categories as $category) {
$tests = array($category->category_parent);
foreach ($tests as $trys) {
$groups[] = $trys;
}
}
$qi = implode(', ', $groups);
$qi = str_replace('0,','',$qi); // remove the 0 id
// result parent category ids' as 1,1,2,2,2 . Tested with echo $qi and the result is just that.
?>
<?php
$display_categories = array($qi);$i = 1; // This is the problem area. It accepts 1,2,2,1,1 manually, but with the variable $qi it just picks the first number?
foreach ($display_categories as $category) { ?>
<div id="fr_cat-<?php echo $i; ?>" class="fr_cat_nav">
<?php query_posts("showposts=1&cat=$category")?>
// Do stuff e.g. <?php echo get_category_link($category);?>
</div>
<?php $i++; ?>
<?php } ?>
Anybody have a take on what could be going wrong?