is_tag()
最后更新于:2021-11-27 11:31:26
is_tag( int|string|int[]|string[]$tag=”)Determines whether the query is for an existing tag archive page.
参数
- $tag
-
(int|string|int[]|string[]) (Optional) Tag ID, name, slug, or array of such to check against.
Default value: ”
响应
(bool) Whether the query is for an existing tag archive page.
源文件
文件: gc-includes/query.php
function is_tag( $tag = '' ) {
global $gc_query;
if ( ! isset( $gc_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 $gc_query->is_tag( $tag );
}
// When any Tag archive page is being displayed. is_tag(); // When the archive page for Tag 30 is being displayed. is_tag( '30' ); // When the archive page for tag with the Slug of 'extreme' is being displayed. is_tag( 'extreme' ); // When the archive page for tag with the Name of 'mild' is being displayed. is_tag( 'mild' ); /* * 响应s true when the tag of posts being displayed is either term_ID 30, * or slug "extreme", or name "mild". Note: the array ability was added * at Version 3.7. */ is_tag( array( 30, 'mild', 'extreme' ) );