欢迎莅临阿Q的项目

专业WP商业设计开发销售中心

[手册]WordPress 条件判断标签(Conditional Tags)

The Main Page 首页,is_home(),判断是否为首页.The Front Page 首页头版消息设置,is_front_page()...

The Main Page 首页

is_home()
判断是否为首页.

The Front Page 首页头版消息设置

is_front_page()
判断是否为首页头版消息. (无论是日志或是页面).当系统显示博客主页且管理面板的设置>阅读菜单下 “主页显示为”选项设为最近发表的文章”,或者'设置>阅读菜单下"主页显示为"选项设为且"主页"是当前被显示的页面时,is_front_page() 标签返回TRUE。

The Administration Panels 管理控制面板

is_admin()
判断是否为后台管理控制面板.

A Single Post Page 单篇日志

is_single()
判断是否为任何单篇日志.
is_single('17')
判断是否为ID17的单篇日志.
is_single('Irish Stew')
判断是否标题为"Irish Stew"的单篇日志.
is_single('beef-stew')
判断是否别名为 "beef-stew"的单篇日志.
is_single(array(17,'beef-stew','Irish Stew'))
判断是否为ID17, 或别名为"beef-stew", 或标题为 "Irish Stew"的单篇日志.
is_single(array(17, 19, 1, 11))
判断是否为ID 17, 19, 1, 11 的文章.
is_single(array('beef-stew', 'pea-soup', 'chili'))
判断是否别名为 "beef-stew", 别名为 "pea-soup" 或 别名为 "chili" 的单篇日志.
is_single(array('Beef Stew', 'Pea Soup', 'Chili'))
判断是否标题为 "Beef Stew",标题为 "Pea Soup" 或标题为 "Chili" 的单篇日志.

A Sticky Post 置顶文章

is_sticky()
判断是否为置顶文章.
is_sticky('17')
判断是否为ID17的置顶文章.

A Post Type

is_post_type($post_type)
Returns true if the value in $post_type is a valid registered post type. This should not be confused with testing to see if a given post is of a particular post type. Note: this conditional tag became available with Version 3.0.
is_post_type('book')
Returns true if book is a registered post type.

A Post Type is Hierarchical

is_post_type_hierarchical($post_type)
Returns true if this $post_type has been set with hierarchical support when registered. Note: This ability was added at Version 3.0.
is_post_type_hierarchical('book')
Returns true if the book post type was registered as having support for hierarchical.

A Comments Popup 评论的弹出窗口

is_comments_popup()
判断是否为评论的弹出窗口.

Any Page Containing Posts 评论

comments_open()
判断当前文章是否允许评论.
pings_open()
判断当前文章是否允许广播(pingback).

A PAGE Page 页面

is_page()
判断是否任何页面.
is_page('42')
判断是否ID 42的页面.
is_page('About Me And Joe')
判断是否标题为"About Me And Joe" 的页面.
is_page('about-me')
判断是否别名为 "about-me" 的页面.
is_page(array(42,'about-me','About Me And Joe'))
判断是否为 ID 42, 或别名 "about-me", 或标题 "About Me And Joe" 的页面.

A Category Page 分类归档

is_category()
判断是否为任何分类页.
is_category('9')
判断是否为ID9的分类页.
is_category('Stinky Cheeses')
判断是否名称为 "Stinky Cheeses"的分类归档页.
is_category('blue-cheese')
判断别名是否为 "blue-cheese"的分类归档页.
is_category(array(9,'blue-cheese','Stinky Cheeses'))
判断是否ID为 9, 或者别名为 "blue-cheese", 或者名称为 "Stinky Cheeses"的分类归档页.
in_category('5')
判断当前文章的分类ID是否为5
in_category( array( 1,2,3 ) )
判断当前文章的分类ID是否为 1, 2, 或 3.
!in_category( array( 4,5,6 ) )
判断当前文章的分类ID是否不是 4, 5, 或 6 .

A Tag Page 标签归档

is_tag()
判断是否为标签页
is_tag('mild')
判断是否为别名 'mild' 的标签归档页.
is_tag(array('sharp','mild','extreme'))
判断别名是否为 "sharp", "mild", 或 "extreme" 的标签归档页.
has_tag()
判断当前文章是否有标签.
has_tag('mild')
判断当前文章是否有标签 'mild'.
has_tag(array('sharp','mild','extreme'))
判断当前文章是否包含一个数组中的标签.

A Taxonomy Page 分类法页面

is_tax()
显示任何分类法归档页面时,is_tax()会返回TRUE。.
is_tax('mild')
示分类法归档页面别名为“mild”时, is_tax('mild')返回TRUE.
is_tax(array('sharp','mild','extreme'))
当前分类法归档别名为数组中的任一个"sharp", "mild", 或 "extreme"时,is_tax(array('sharp','mild','extreme')) 返回TRUE.

A Registered Taxonomy 注册过的分类法

is_taxonomy()
当某一种分类法通过register_taxonomy()注册, is_taxonomy()  返回TRUE.

An Author Page 作者归档

is_author()
判断是否为作者归档页.
is_author('4')
判断是否为ID4的作者归档页.
is_author('Vivian')
判断是否为昵称 "Vivian"的作者归档页.
is_author('john-jones')
判断是否为昵称 "john-jones" 的作者归档页.
is_author(array(4,'john-jones','Vivian'))
判断是否为 ID 4, 或者昵称 "john-jones", 或昵称 "Vivian" 的作者标签页.

A Date Page 日期归档页

is_date()
判断是否为日期归档页.
is_year()
判断是否为按年归档页.
is_month()
When a monthly archive is being displayed.
is_day()
判断是否为按天归档页.
is_time()
判断是否按小时, "分钟", "秒"归档页.

Any Archive Page 归档页

is_archive()
是否归档页.

A Search Result Page 搜索结果页

is_search()
是否搜索页.

A 404 Not Found Page 未找到页面

is_404()
是否404页面.

A Paged Page 分页

is_paged()
判断是否有分页. 需要将 <!--nextpage--> 快速标签插入到文章中才能将文章分成多页.

An Attachment 附件

is_attachment()
判断是否为附件文档. 附件是通过编辑器上传工具上传的图片或其他文件. 附件能显示在相应的页面或模版中.

A Single Page, Single Post or Attachment 独立页面、单篇日志或附件

is_singular()
当is_single(), is_page() 或is_attachment()返回TRUE时,is_singular() 也返回TRUE。.
is_singular('book')
True when viewing a post of the post type book. Introduced with Version 3.0.
is_singular(array( 'newspaper', 'book' ))
True when viewing a post of the post type newspaper or book. Introduced with Version 3.0.

A Syndication

is_feed()
网站需要使用RSS订阅时,is_feed()返回TRUE。一般情况下会用到is_feed()标签的是WordPress系统和插件开发人员,普通 WordPress用户很少用到is_feed()标签.

A Trackback 引用通知

is_trackback()
网站需要将WordPress钩子勾入Trackback。一般情况下会用到这个标签的是WordPress系统和插件开发人员,普通WordPress 用户很少用到is_feed()标签.

A Preview 草稿预览

is_preview()
判断文章是否显示在草稿预览模式.

Has An Excerpt 摘要

has_excerpt()
判断当前文章是否有摘要.
has_excerpt('42')
判断ID42的文章是否有摘要.

Inside The Loop 循环

in_the_loop()
判断目前是否在WordPress主循环中. 该标签适用于插件开发人员, 若目前在WordPress主循环中, 该标签返回TRUE.

Is Sidebar Active 边栏

is_active_sidebar()
检查现有侧边栏是否被激活(是否启用).若侧边栏被启用,is_active_sidebar() 返回TRUE,否则返回FALSE.

详情见:http://codex.wordpress.org/Conditional_Tags

如果喜欢本文,请分享给朋友们

[手册]WordPress 条件判断标签(Conditional Tags)6 篇评论

  1. 好友意思的评论验证~
    O(∩_∩)O谢谢,分的很详细

  2. 大门五郎

    文章不错,支持一下!

  3. 晴小妹

    第一次到你博客,感觉不错!