How to Display Category Description in Wordpress?

Discussion in 'WordPress' started by acepsdr, Aug 13, 2008.

  1. #1
    I want display category description in wordpress (I'm using 2.6 version) and I try use <?php echo category_description(); ?>, but the category description can't display. But if I add category ID like this <?php echo category_description(5); ?>, the category description is show (can display).

    What is wrong?
     
    acepsdr, Aug 13, 2008 IP
  2. mizaks

    mizaks Well-Known Member

    Messages:
    2,066
    Likes Received:
    126
    Best Answers:
    0
    Trophy Points:
    135
    #2
    Nothing is wrong. That is how the tag works.

    You need to use the "single_cat_title" tag in conjunction with the "category_description" tag for what you want. More info here.
     
    mizaks, Aug 13, 2008 IP
  3. acepsdr

    acepsdr Peon

    Messages:
    37
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I try using like this, but it's the same (can't display):

    <p><?php single_cat_title('Currently browsing'); ?>
    <?php echo category_description(); ?></p>

    New Info:
    I look at address browser, if ...../?cat=x category description show (can display) with category_description(). But if address browser like this: ....../?p=x category description can't display with category_description() script. My new Question now, how to display category description if at address browser like "?p=x" ?
     
    acepsdr, Aug 13, 2008 IP
  4. acepsdr

    acepsdr Peon

    Messages:
    37
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    It's can or not to do?
     
    acepsdr, Aug 14, 2008 IP
  5. Cash Nebula

    Cash Nebula Peon

    Messages:
    1,197
    Likes Received:
    67
    Best Answers:
    0
    Trophy Points:
    0
    #5
    single_cat_title only works outside the loop, and category_description only works on a category page if no category is given. Maybe that's wrong but that's how I read it.

    Do you want to show the category description for a post? Try this inside the loop:
    
    <?php
       $category = get_the_category(); 
       echo category_description($category[0]->cat_ID);
    ?>
    
    Code (markup):
    It should show the first category description for a post. To show a description for each category, you'll need to make it loop through each one.
     
    Cash Nebula, Aug 14, 2008 IP