确定查询是否针对现有类别存档页面。
原型
is_category( mixed $category = '' )
描述
如果指定了$ category参数,则此函数将另外检查查询是否针对指定的类别之一。
参数
$category
(mixed)
(Optional)
类别ID,名称,slug或类别ID,名称和slug的数组。
返回值
(bool)
源文件
路径:wp-includes/query.php
<?php
...
function is_category( $category = '' ) {
global $wp_query;
if ( ! isset( $wp_query ) ) {
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' );
return false;
}
return $wp_query->is_category( $category );
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/is_category/