admin管理员组文章数量:1023273
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?
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-
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 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 - @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 Commented Dec 26, 2010 at 3:57
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?
本文标签: categoriesecho category description in singlephp
版权声明:本文标题:categories - echo category description in single.php 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745593289a2158013.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