功能:
is_single()函数是WordPress的页面判断函数之一,用来判断当前页面是否是文章页。
用法:
参数:
$post
(int|string|array) (可选的) 文章ID、名称、别名、或者文章ID、名称、别名的数组.
默认:”
返回值:
(bool) 是指定的文章页就返回True,其他页面都返回False
所在位置:
is_single()函数包含在 wp-includes/query.php中.
源码:
/**
* Is the query for an existing single post?
*
* Works for any post type, except attachments and pages
*
* If the $post parameter is specified, this function will additionally
* check if the query is for one of the Posts specified.
*
* @see is_page()
* @see is_singular()
*
* @since 1.5.0
*
* @global WP_Query $wp_query Global WP_Query instance.
*
* @param int|string|array $post Optional. Post ID, title, slug, or array of such. Default empty.
* @return bool Whether the query is for an existing single post.
*/
function is_single( $post = '' ) {
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_single( $post );
}
示例:
相关函数:
感觉本站内容不错,读后有收获?小额赞助
还可以分享文章给好友:
不知道在页面中怎么使用