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.
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 edited Dec 26, 2010 at 4:00 andrewk asked Dec 25, 2010 at 22:13 andrewkandrewk 1711 gold badge2 silver badges17 bronze badges 2 |1 Answer
Reset to default 5Try the code that follows the screenshot:
(source: mikeschinkel)
<?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?
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745593290a4634958.html
category.php
where you are displaying the code where it works and where insingle.php
you want the code to work? Where you want to use it matters a bit. – MikeSchinkel Commented Dec 26, 2010 at 3:27