wp_list_categories to show list of categories and the description

I have some code in my category.php file to show either pages or categories. Depending if the category has sub categories or not. Is it possible to also show the category description as well?

This is the code i’m using to show either the pages or a list of categories in my category.php file.

Read More
<?php

if (!category_has_children()) {?>
<?php foreach(get_the_category() as $category) {
$cat = $category->cat_ID; }?>
<?php query_posts('post_type=Product&cat=' .$cat .'&order=ASC'); ?>
            <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
            <p><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a><?php the_post_thumbnail(array(100,100)); ?>
            <?php the_excerpt(); ?></p>
                    <?php endwhile;?>
        <?php endif; ?> 
<?php get_template_part('loop', 'index');
} else {?></div><!-- /productlist -->
<div id="productcategories"><h1>
<?php 
$cat_id = get_query_var('cat');
$catlist = get_categories('child_of=' . $cat_id);
if ($catlist) {
wp_list_categories('depth=1&hide_empty=0&echo=1&orderby=id&title_li=&child_of=' . $cat_id);
} 
}
?>

I don’t think it’s important but i’ve also got this code in my functions.php file.

//Display product categories
function category_has_children() {
global $wpdb;
$term = get_queried_object();
$category_children_check = $wpdb->get_results(" SELECT * FROM wp_term_taxonomy WHERE parent = '$term->term_id' ");
     if ($category_children_check) {
          return true;
     } else {
          return false;
     }
}

I don’t think a lot of the code is important but thought i should show everything. I need to use the wp_list_categories because i have a plugin that displays an image next to category names and that needs to use the wp_list_categories function.

Related posts

Leave a Reply

1 comment