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.


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>
$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.

  • Can you archieve this? I have the same problem
    – xzegga
    Commented Jun 23, 2015 at 7:10

1 Answer 1


i think that wp_list_categories show categories already formated with <li> tags and you should try using get_categories which leaves the display to you. eg show list of categories and the description

echo "<ul>";
foreach($all_categories as $categories_item)
  echo "<li>".$categories_item->description."</li>";//you get the idea
echo "</ul>";

EDIT: i saw exactly what you need here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.