Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

i asked this on SO but got no where. i will try asking here.

this works fine in category.php <?php echo category_description(the_category_id()); ?>

but it does not work in single.php, just the category id shows up not the description.

any ideas, how to get this done?

thanks in advance

Edit:

in category: <?php echo strip_tags(category_description(4)); ?>

in single <?php echo category_description(the_category_id()); ?> cat id = 4

i know i'm not striping the tags..for single

i'm just trying to display the cat desc when in the single post page.

share|improve this question
    
Not surprising you'd get no help for WordPress at SO; they are not WordPress enthusiasts, we are. :) Can you please provide some context for your question? Can you show the code from category.php where you are displaying the code where it works and where in single.php you want the code to work? Where you want to use it matters a bit. –  MikeSchinkel Dec 26 '10 at 3:27
    
@Mike thanks, actually in both cases(single + cat) I am calling the function outside the loop..right before the loop starts... i edited the q a bit. –  andrewk Dec 26 '10 at 3:57

1 Answer 1

up vote 2 down vote accepted

Hi @andrewk -

Try the code that follows the screenshot:

Displaying WordPress Category Description

<?php
  $categories = get_the_category();
  foreach($categories as $key => $category) {
    $url = get_term_link((int)$category->term_id,'category');
    $categories[$key] =
      "<dt><a href=\"{$url}\">{$category->name}</a></dt>" .
      "<dd>{$category->category_description}</dd>";
  }
  echo "<dl>\n" . implode("\n",$categories) . "\n</dl>";
?>

Also, <?php echo category_description(the_category_id()); ?> doesn't do what you think it does. What follows will work on your category pages because it assumes the category ID for the category page:

<?php echo category_description(); ?>

FYI, the_category_id() will echo the value of the current category ID, it doesn't actually pass anything to category_description() is looks like was your assumption. Besides, the_category_ID() is deprecated so you wouldn't want to use it anyway. By the way, I'll bet you are seeing an errant number being displayed just before the category description is displayed?

share|improve this answer
    
@Mike you rock. thanks a bunch. all of your answers are so straightforward. You are bettering the world. thanks man. –  andrewk Dec 26 '10 at 5:04
    
@andrewk - You are welcome. :) Happy Holidays. –  MikeSchinkel Dec 26 '10 at 7:52
    
hey @mike take a look at this.. stackoverflow.com/questions/4529618/… it seems simple.I appreciate both. –  andrewk Dec 26 '10 at 21:15
    
@andrewk - Yes, his is simple but it does less. His only gets the first category and does not hyperlink it. Mine gets all categories assigned to a post and formats them nicely including with hyperlinks. I usually try to anticipate the things you are going to want and need and thus give more complete answers. So his is an engine. Mine is a complete car that includes an engine. :) Hope this helped. –  MikeSchinkel Dec 27 '10 at 19:02
    
As always, I have learned a lot from your answer - thanks Mike. –  davemac Feb 28 '11 at 12:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.