功能:
is_tag()函数是WordPress的页面判断函数之一,用来判断当前页面是否是标签页。
用法:
参数:
$tag
(mixed) (可选的) 标签ID、名称、别名或者标签ID、名称、别名的数组
默认: None
返回值:
(bool) 是指定的标签页就返回True,否则返回False
所在位置:
is_tag()函数包含在 wp-includes/query.php中.
源码:
/**
* Is the query for an existing tag archive page?
*
* If the $tag parameter is specified, this function will additionally
* check if the query is for one of the tags specified.
*
* @since 2.3.0
*
* @global WP_Query $wp_query Global WP_Query instance.
*
* @param mixed $tag Optional. Tag ID, name, slug, or array of Tag IDs, names, and slugs.
* @return bool
*/
function is_tag( $tag = '' ) {
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' );
return false;
}
return $wp_query->is_tag( $tag );
}