WordPress.org

Ready to get started?Download WordPress

Forums

Category description. Please, help. (11 posts)

  1. ladymf
    Member
    Posted 6 years ago #

    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

  2. MichaelH
    Member
    Posted 6 years ago #

    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.

  3. ladymf
    Member
    Posted 6 years ago #

    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

  4. ladymf
    Member
    Posted 6 years ago #

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

  5. drew3000
    Member
    Posted 6 years ago #

    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.

  6. MichaelH
    Member
    Posted 6 years ago #

    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
    }
    ?>
  7. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    I added a trac ticket, so this may get implemented in some future version: http://trac.wordpress.org/ticket/4601

  8. estjohn
    Member
    Posted 6 years ago #

    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?

  9. syncbox
    Member
    Posted 6 years ago #

    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!

  10. syncbox
    Member
    Posted 6 years ago #

    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.

  11. gurrupurru
    Member
    Posted 6 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic