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'm using the following code to show the subcategories of a category within my archive.php page:

<?php if (is_category()) {
  $this_category = get_category($cat);
  if (get_category_children($this_category->cat_ID) != "") {
    echo "<div id='catlist'><ul>";
    wp_list_categories('orderby=name&hide_empty=0&title_li=&use_desc_for_title=1&child_of='.$this_category->cat_ID);
    echo "</ul></div>";
  }
}?>

The code above returns the name of the category as a link, with the category description as the link title.

Can anyone show my how to show the category description within paragraph tags after the category link?

Thanks.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

wp_list_categories formats the results, instead you want to try get_categories and create your own loop to format the results.

I do not know exactly how you want it formated, but this gives you the general idea.

<?php 
if (is_category()) {
    $this_category = get_category($cat);
    if (get_category_children($this_category->cat_ID) != "") {
        echo '<div id="catlist"><ul>';
        $childcategories = get_categories(array(
            'orderyby' => 'name',
            'hide_empty' => false,
            'child_of' => $this_category->cat_ID
            ));
        foreach($childcategories as $category) {
            echo '<a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a>';
            echo '<p>'.$category->description.'</p>';
        }
        echo '</ul></div>';
    }
}
?>

For more examples and information visit, get_categories

share|improve this answer
    
That is perfect, thank you! :) –  Darren Aug 4 '11 at 15:49
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.