条件标签是一种布尔数据类型,可在模板文件中使用,根据当前页面符合的条件来改变内容的显示方式。它们用于告知WordPress在特定条件下应显示何种代码。条件标签通常与PHP的if/else条件语句配合使用,并与WordPress的模板层级结构密切相关。
警告:只有在WP_Query已被设置,或通过动作钩子实现的情况下,才能使用条件查询标签。
所有条件标签列表
- is_front_page()
- is_home()
- is_front_page()
- is_home()
- is_admin()
- is_network_admin()
- is_admin_bar_showing()
- is_single()
- is_sticky()
- is_post_type_hierarchical( $post_type )
- is_post_type_archive()
- is_comments_popup()
- comments_open()
- pings_open()
- is_page()
- is_page_template()
- is_category( $category )
- is_tag()
- is_tax()
- has_term()
- term_exists( $term, $taxonomy, $parent )
- is_taxonomy_hierarchical( $taxonomy )
- taxonomy_exists( $taxonomy )
- is_author()
- is_date()
- is_year()
- is_month()
- is_day()
- is_time()
- is_new_day()
- is_archive()
- is_search()
- is_404()
- is_paged()
- is_attachment()
- wp_attachment_is_image( $post_id )
- is_local_attachment( $url )
- is_singular()
- post_type_exists( $post_type )
- is_main_query()
- is_new_day()
- is_feed()
- is_trackback()
- is_preview()
- in_the_loop()
- is_dynamic_sidebar()
- is_active_sidebar()
- is_active_widget( $widget_callback, $widget_id )
- is_blog_installed()
- is_rtl()
- is_multisite()
- is_main_site()
- is_super_admin()
- is_user_logged_in()
- email_exists( $email )
- username_exists( $username )
- is_plugin_active( $path )
- is_plugin_inactive( $path )
- is_plugin_active_for_network( $path )
- is_plugin_page()
- is_child_theme()
- current_theme_supports()
- has_post_thumbnail( $post_id )
- wp_script_is( $handle, $list )
各条件的判定标准
所有的条件标签都会检测某一特定条件是否成立,然后返回TRUE或FALSE。下面列出了各类标签返回TRUE的条件,那些可以接受参数的标签已在相应位置标注。
首页
前台首页
博客页面
单篇文章页面
页面类型页面
是否有文章缩略图
单页、单篇文章、附件或任何其他自定义文章类型
分类页面
标签页面
分类法页面(及相关页面)
- is_tax()
- has_term()
- term_exists( $term, $taxonomy, $parent )
- is_taxonomy_hierarchical( $taxonomy )
- taxonomy_exists( $taxonomy )
作者页面
日期页面
任何归档页面
搜索结果页面
404错误页面
是否为动态侧边栏
侧边栏是否处于激活状态
小部件是否处于激活状态
用户是否已登录
电子邮件是否存在
用户名是否存在
分页页面
从右至左阅读模式
附件
附件是否为图片
本地附件
文章类型是否存在
是否为主查询
新的一天
信息聚合页面
追踪回访页面
预览页面
是否有摘要
是否有导航菜单
是否安装了博客系统
是否属于多站点系统
是否有激活的插件
- is_plugin_active( $path )
- is_plugin_inactive( $path )
- is_plugin_active_for_network( $path )
- is_plugin_page()