我正在使用wordpress,我想知道在使用时如何获得帖子类别的永久链接和名称:
<?php the_category() ?>
上面输出一个列表,我只想在自己的标记中包装永久链接和类别
答案 0 :(得分:8)
我想你想要get_the_category()
和get_category_link()
:
<?php
// everything available
foreach((get_the_category()) as $category) {
echo '<span><b>';
echo $category->cat_ID . ' ';
echo $category->cat_name . ' ';
echo $category->category_nicename . ' ';
echo $category->category_description . ' ';
echo $category->category_parent . ' ';
echo $category->category_count . ' ';
echo '</b></span>';
}
?>
<?php
// heres just the name and permalink:
foreach((get_the_category()) as $category) {
echo $category->category_nicename . ' ';
echo get_category_link($category->cat_ID);;
}
?>