is_author()判断当前页面是否是作者存档页面

目录

描述

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

is_author() 描述

用法

<?php is_author($author); ?>

is_author() 用法

参数

$author

(mixed) (可选) Author ID or Author Nickname

默认值: None

is_author() 参数

返回值

(boolean) 

True on success, false on failure.

is_author() 返回值

示例

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

is_author('4');
// When the archive page for Author number (ID) 4 is being displayed.

is_author('Vivian');
// When the archive page for the Author with Nickname "Vivian" is being displayed.

is_author('john-jones');
// When the archive page for the Author with Nicename "john-jones" is being displayed.

is_author(array(4,'john-jones','Vivian'));
// When the archive page for the author is either user ID 4, or user_nicename "john-jones", or nickname "Vivian".  Note: the array ability was added at Version 2.5.

is_author() 示例

注意

历史

添加于 版本 Version 1.5

is_author() 历史

源文件

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

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Is the query for an existing author archive page?
 *
 * If the $author parameter is specified, this function will additionally
 * check if the query is for one of the authors specified.
 *
 * @since 1.5.0
 *
 * @global WP_Query $wp_query
 *
 * @param mixed $author Optional. User ID, nickname, nicename, or array of User IDs, nicknames, and nicenames
 * @return bool
 */
function is_author( $author = '' ) {
	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_author( $author );
}

is_author() 源文件

相关