WordPress.org

Support

Support » Themes and Templates » Category description. Please, help.

Category description. Please, help.

  • Hi, I’m trying to launch a photoblog http://czech-photos.com/(It's not ready yet.) and I got a little problem.

    I’m not familiar with PHP at all ((
    I wanna display descriptions next to each category name on index page.

    I edited the code like this:

      <?php wp_list_cats(‘sort_column=name’); ?> – <?php echo category_description($cat); ?>

    but it doesn’t work properly 🙁

    Could you please advice?
    Thank you very much for your help

    Kateryna

Viewing 10 replies - 1 through 10 (of 10 total)
  • 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.

    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

    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(‘); ?>

    drew3000
    Participant

    @drew3000

    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.wordpress.org/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.

    gurrupurru
    Member

    @gurrupurru

    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.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Category description. Please, help.’ is closed to new replies.