0

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.

1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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