php 检查当前页面是否是wordpress中的类别页面?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19558545/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Check if current page is category page in wordpress?
提问by Amit Garg
I have to insert some condition if the current page is a category page or not.
如果当前页面是类别页面,我必须插入一些条件。
回答by Amit Garg
I have found the way to do it by checking if $cat_id
is available or not that page by the following.
我找到了通过以下方式检查$cat_id
该页面是否可用的方法。
$cat_id = get_query_var('cat');
Now we can check if $cat_id is available then it is a category page otherwise it is not.
现在我们可以检查 $cat_id 是否可用,那么它是一个类别页面,否则它不是。
回答by Jigar Patel
you can use this for getting category
您可以使用它来获取类别
is_category();
is_category( '1' ); // where 1 is category id
is_category( 'test' ); // where test is category name
is_category( 'test-ing' ); // where test-ing is category slug
回答by Yatendra
You can use
您可以使用
is_category();
function.
功能。
refrence: http://codex.wordpress.org/Function_Reference/is_category
参考:http: //codex.wordpress.org/Function_Reference/is_category
回答by Tom Webb
Amit's answer will work but there is a simpler way as Wordpress sets a Global var for the category id of $cat. So just checking if this is set will tell you if you are on a category page.
Amit 的答案会起作用,但有一种更简单的方法,因为 Wordpress 为 $cat 的类别 id 设置了全局变量。所以只要检查是否设置了它就会告诉你你是否在一个类别页面上。
if(!empty($cat)){ //do something just on a category archive page }