Don’t see what version you are using so assuming it is 2.2.1, consider using the template tag, wp_list_categories(). There’s a number of examples listed in that Codex article.
Thread Starter
ladymf
(@ladymf)
Thanks for reply, but I’ve already checked all parameters for wp_list_categories()
and haven’t found what I need.
“use_desc_for_title” changes the “title” tag and doesn’t let to display the description next to category name
Thread Starter
ladymf
(@ladymf)
I need something like show_description parameter that exists for <?php get_links(); ?>
but I can’t find anything like it for <?php wp_list_cats(‘); ?>
Interesting. I’m looking for something similar. No one seems to have the answer. Seems like is would be a short strip of code but I can’t figure what it would be.
Maybe not the simplest but seems to work:
<?php
$categories = get_categories("hide_empty=1&type=post");
foreach ((array) $categories as $cat) {
$cat_link = '<a href="' . get_category_link($cat->cat_ID) . '" title="' . sprintf(__("View all posts in %s"), $cat->cat_name) . '" ' . $rel . '>' . $cat->cat_name.'</a>';
?>
<p><?php echo $cat_link . ' ' . $cat->category_description; ?></p>
<?php
}
?>
I added a trac ticket, so this may get implemented in some future version: http://trac.ww.wp.xz.cn/ticket/4601
On mine – ericastjohn.com
The sidebar which contain the categories are listed at the bottom of the page. When I hover the mouse over the category name, it shows what I used as the category description
The code in mine for this is
<?php wp_list_cats('sort_column=name&optioncount=1&hierarchical=0'); ?>
Would that be what you mean?
Thanks, MichaelH! I was able to take your code as a starting point and get done what I wanted, which was to show a list of sub-categories for a parent category, with the category description of each below each bullet point! YAY!
Here’s my code, in case others are interested in this solution:
<ul id="catlist">
<?php
$categories = get_categories("title_li=&orderby=name&hide_empty=0&child_of=54");
foreach ((array) $categories as $cat) {
$cat_link = '<a href="' . get_category_link($cat->cat_ID) . '" title="' . sprintf(__("View all posts in %s"), $cat->cat_name) . '" ' . $rel . '>' . $cat->cat_name.'</a>';
?>
<li><?php echo $cat_link . '<span>' . $cat->category_description; ?></span></li>
<?php
}
?>
</ul>
I set up styles for the span tags in ul#catlist li span {}
to display:block; forcing the span (with the description) to be a new block.
AWESOME. I love WP. I love this forum!
You all rock!
Actually, I’ve modified this… I stripped out the span and class and am taking advantage of the fact that I modified my functions file to stop html filtering (removing) in category descriptions. I put p tags in those, then set up a style for p tags when in a #catlist li
ul#catlist li p {}
works great and simpler, plus the p tags in the li tags check out as valid.
Hi, people! I need this function to pass throught the filter of the Polyglot plugin, so I can get just the description in the current language. Is it possible to achieve this? Thanks in advance.