WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to display category desc in list of sub cats (5 posts)

  1. syncbox
    Member
    Posted 6 years ago #

    I understand how to create a list of sub-categories and get each cat's description used for the title attribute of the link...

    what I'd like to do is use the same category description in a span after the name of the category is written... basically, if I use this:

    <ul>
    <?php wp_list_categories('title_li=&orderby=name&use_desc_for_title=1&child_of=8'); ?>
    </ul>

    I get something like:

    category A
    category B
    category C

    where each is a bulleted list item. OK... and hovering over each displays a tooltip with the text from the cat desc (too bad you cannot have line breaks in these any more!)

    What I want is this:

    category A
    blah, blah, blah for cat A
    category B
    blah, blah, blah for cat B

    etc

    There's no way to interject an echo for each list item using the template tag wp_list_categories();

    Ideas, anyone? Much appreciated!!

  2. syncbox
    Member
    Posted 6 years ago #

    thanks to MichaelH for a starting bit of code, I am using this:

    <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 . '' . $cat->category_description; ?></li>
    <?php
    }
    ?>
    </ul>

    to solve my needs. It works and because I have disabled the html stripping of category descriptions, I can style the paragraphs of the description as needed.

    I love WP. I love this forum!

  3. ringostar
    Member
    Posted 6 years ago #

    anyway to add the post count to this ?

  4. ignitionmedia
    Member
    Posted 6 years ago #

    Just to expand on this post.. Essentially this does everything I want however I want this result from a category template...

    I need the category template to list by default the title, description (and category image using the 'Category icons' Plugin) of each sub category of the parent category.

    the code above you have to specify a Cat_ID.. how would I have it do this?

    any help is appreciated

  5. submarine
    Member
    Posted 5 years ago #

    Hi,

    with category icons plugin, just use :
    get_cat_icon('cat='.$cat->cat_ID);

    http://www.category-icons.com

Topic Closed

This topic has been closed to new replies.

About this Topic