I have to insert some condition if the current page is a category page or not.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
I have found the way to do it by checking if $cat_id
is available or not on that page by the following.
$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.
回答2:
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
回答3:
You can use
is_category();
function.
refrence: http://codex.wordpress.org/Function_Reference/is_category
回答4:
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.
if(!empty($cat)){ //do something just on a category archive page }