sltone9
Member
Posted 4 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.
<ul>
<?php
$categories= get_categories();
foreach ($categories as $cat) {
echo '<li>'.'<a href="'.get_category_link($cat->cat_ID).'">'.$cat->description.'</a>'.'</li>';
}
?>
</ul>
davidhosier
Member
Posted 4 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 />';
}
?>
emanoelmelo
Member
Posted 3 years ago #
This was quite what i was looking for, thank you guys!