is_single()
最后更新于:2021-11-27 11:03:05
is_single( int|string|int[]|string[]$post=”)Determines whether the query is for an existing single post.
参数
- $post
-
(int|string|int[]|string[]) (Optional) Post ID, title, slug, or array of such to check against.
Default value: ”
响应
(bool) Whether the query is for an existing single post.
源文件
文件: gc-includes/query.php
function is_single( $post = '' ) {
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_single( $post );
}
is_single(); // When any single Post page is being displayed. is_single('17'); // When Post 17 (ID) is being displayed. is_single(17); // When Post 17 (ID) is being displayed. Integer parameter also works is_single('Irish Stew'); // When the Post with post_title of "Irish Stew" is being displayed. is_single('beef-stew'); // When the Post with post_name (slug) of "beef-stew" is being displayed. is_single(array(17,'beef-stew','Irish Stew')); // 响应s true when the single post being displayed is either post ID 17, // or the post_name is "beef-stew", or the post_title is "Irish Stew". // Note: the array ability was added in version 2.5.