說明
wordpress 判斷一個單獨一面是否被顯示,返回 TRUE 或者 FALSE
用法
- <?php?is_single($post);??>
參數
$post
(mixed) (optional) Post ID, Post Title or Post Slug
默認: None
返回值
(boolean)
成功 True, 失敗 false.
示例
- is_single();
- is_single('17');
- is_single(17);
- is_single('Irish?Stew');
- is_single('beef-stew');
- is_single(array(17,'beef-stew','Irish?Stew'));
注意
類似功能: is_singular()
源文件
is_single() 在 wp-includes/query.php.
- 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?);
- }
- ?function?is_single(?$post?=?''?)?{
- ??if?(?!$this->is_single?)
- ???return?false;
- ??if?(?emptyempty($post)?)
- ???return?true;
- ??$post_obj?=?$this->get_queried_object();
- ??$post?=?(array)?$post;
- ??if?(?in_array(?$post_obj->ID,?$post?)?)
- ???return?true;
- ??elseif?(?in_array(?$post_obj->post_title,?$post?)?)
- ???return?true;
- ??elseif?(?in_array(?$post_obj->post_name,?$post?)?)
- ???return?true;
- ??return?false;
- ?}