检查当前页面是否是wordpress中的类别页面?

Ami*_*arg 7 php wordpress

如果当前页面是类别页面,我必须插入一些条件.

Ami*_*arg 8

我已经找到了通过以下方式检查$cat_id该页面是否可用的方法.

$cat_id = get_query_var('cat');
Run Code Online (Sandbox Code Playgroud)

现在我们可以检查$ cat_id是否可用,然后它是一个类别页面,否则它不是.

  • 提及≠解释 (2认同)

Yat*_*dra 6

您可以使用

is_category();
Run Code Online (Sandbox Code Playgroud)

功能。

参考:http : //codex.wordpress.org/Function_Reference/is_category

  • 谢谢@Yatendra!我尝试过该功能,但无法区分页面是帖子页面还是类别页面。 (3认同)

小智 6

你可以用它来获取类别

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
Run Code Online (Sandbox Code Playgroud)