admin管理员组文章数量:1305140
Using the following code in a category template, but instead of showing the current category page that I am on, it displays the first category of the first post. For example on Food category page it should say Food, but instead it says Desserts because the first post's category is desserts. Here is the site /
add_action ( 'genesis_before_content', 'sk_show_category_name' );
function sk_show_category_name() {
$category = get_the_category();
if (is_category()) {
echo '<div id="cat-name">' . $category[0]->cat_name . '</div>';
}
}
Using the following code in a category template, but instead of showing the current category page that I am on, it displays the first category of the first post. For example on Food category page it should say Food, but instead it says Desserts because the first post's category is desserts. Here is the site http://theveganproject.ca/wp/category/food/
add_action ( 'genesis_before_content', 'sk_show_category_name' );
function sk_show_category_name() {
$category = get_the_category();
if (is_category()) {
echo '<div id="cat-name">' . $category[0]->cat_name . '</div>';
}
}
Share
Improve this question
asked Jan 29, 2014 at 23:46
NFdesignNFdesign
1351 gold badge1 silver badge7 bronze badges
2 Answers
Reset to default 43On a category page, you can use the function single_cat_title()
, or the more generic single_term_title()
. These functions pull from the global $wp_query
object, via get_queried_object()
.
You can use single_cat_title('' , true )
this function and add those parameters to removed the prefix.
本文标签: phpDisplay current category title on category page
版权声明:本文标题:php - Display current category title on category page 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741797682a2398032.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论