Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

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

share|improve this question
add comment

1 Answer

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

$all_categories=get_categories();
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
add comment

Your Answer

 
discard

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.