Home  >  Article  >  php教程  >  WordPress中is_singular()函数简介,wordpress函数手册

WordPress中is_singular()函数简介,wordpress函数手册

WBOY
WBOYOriginal
2016-06-13 09:15:321541browse

WordPress中is_singular()函数简介,wordpress函数手册

函数is_singular()检测结果为true,当下面其一返回true时:is_single()、is_page()、is_attachment()。 如果指定了$post_types时,还要检测是否是该类型。

函数原型

复制代码 代码如下:


is_singular( $post_types = '' );

参数详解
$post_types,Post type或者在当前query中的类型。
返回值
检测成功返回true,否则返回false。

应用实例
在singular页面下显示不一样的广告:

复制代码 代码如下:


if( is_singular()){
 // show adv. #1
} else {
 // show adv. #2
}
?>

对于普通的post返回true:

复制代码 代码如下:


is_singular('post');

如果is_single()、is_page()、is_attachement()返回true,则下面函数返回true:

复制代码 代码如下:


is_singular();

对于自定义post type book来说,下面函数返回true:

复制代码 代码如下:


is_singular('book');

总结

在使用分页导航时,在is_singular()时不显示导航。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn