is_tag()判断当前页面是否为标签页面

目录

描述

This Conditional Tag checks if a Tag archive page is being displayed. This is a boolean function, meaning it returns either TRUE or FALSE.

is_tag() 描述

用法

<?php is_tag$tag ); ?>

is_tag() 用法

参数

$tag

(mixed) (可选) Tag ID, name, slug, or array of id's, names, and slugs.

默认值: None

is_tag() 参数

返回值

(boolean) 

True on success, false on failure.

is_tag() 返回值

示例

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
is_tag();
// When any Tag archive page is being displayed.

is_tag( '30' );
// When the archive page for Tag 30 is being displayed.

is_tag( 'extreme' );
// When the archive page for tag with the Slug of 'extreme' is being displayed.

is_tag( 'mild' );
// When the archive page for tag with the Name of 'mild' is being displayed.

is_tag( array( 30, 'mild', 'extreme' ) );
// Returns 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() 示例

注意

is_tag() 注意

历史

  • 添加于 版本: 2.3.0
  • 3.7.0: Make $tag parameter recieve tag ID, name, slug, or array of tag IDs, names, and slugs.

is_tag() 历史

源文件

is_tag() 函数的代码位于 wp-includes/query.php.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * 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
 *
 * @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 );
}

is_tag() 源文件

相关