WordPress.org

Ready to get started?Download WordPress

Forums

List WordPress Categories with Cat Descriptions (4 posts)

  1. sltone9
    Member
    Posted 6 years ago #

    Hi, I had been trying to list the categories with their descriptions (in "ul" unordered list).

    <u>Example:</u>

    Category 1 Link >> This is a description of Category 1
    Category 2 Link >> This is a description of Category 2
    Category 3 Link >> This is a description of Category 3

    ....

    Currently, I have only been able to use the wp_list_categories function and use the cat_description as the title attribute but haven't found a plugin for the above.

  2. Outrix
    Member
    Posted 6 years ago #

    <ul>
     <?php
      $categories=  get_categories();
      foreach ($categories as $cat) {
    	echo '<li>'.'<a href="'.get_category_link($cat->cat_ID).'">'.$cat->description.'</a>'.'</li>';
      }
     ?>
    </ul>
  3. davidhosier
    Member
    Posted 6 years ago #

    Outrix's solution didn't work for me. Here's what did work for me (I hate dealing with unordered lists):

    <?php
    $categories = get_categories();
    foreach ($categories as $cat) {
    	if ($cat->category_parent != 0) {
    		echo '<span style="padding-left:10px;">';
    	}
    	echo '<a href="'.get_option('home').get_option('category_base').'/'.$cat->category_nicename.'/">'.$cat->cat_name.'</a> ('.$cat->category_count.')';
    	if ($cat->category_description != '') {
    		echo ' - '.$cat->category_description;
    	}
    	if ($cat->category_parent != 0) {
    		echo '</span>';
    	}
    	echo '<br />';
    }
    ?>
  4. emanoelmelo
    Member
    Posted 5 years ago #

    This was quite what i was looking for, thank you guys!

Topic Closed

This topic has been closed to new replies.

About this Topic