WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
Can you archieve this? I have the same problem – xzegga Jun 23 '15 at 7:10
up vote 0 down vote accepted

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

share|improve this answer
I have seen that, the problem is the plugin i'm using to show category images (wordpress.org/extend/plugins/category-page-icons) only works with wp_list_categories not get_categories. – Corbula Nov 1 '11 at 12:02

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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