绿站
绿色文摘
今天是:

交流 | 搜索 | +发贴

WordPress条件标签大全
nydalu 2024年5月22日 23次

条件标签是一种布尔数据类型,可以在你的模板文件中使用,以改变内容的显示,取决于当前页面匹配的条件。它们告诉WordPress在特定条件下显示什么代码。条件标签通常与PHP的if/else条件语句一起工作,并与WordPress的模板层次结构有密切关系。

警告:你只能在WP_Query设置后或与动作钩子一起使用条件查询标签。

条件标签的完整列表
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_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_home()

首页
is_front_page()

博客页
is_front_page()
is_home()

文章单页
is_single()

页面
is_page()
is_page_template()

有文章缩略图
has_post_thumbnail( $post_id )

文章单页、单页面、附件、其他任意自定义文章类型
is_singular()

类别页面
is_category( $category )

标签页面
is_tag()
has_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()

404页面
is_404()

侧边栏
is_dynamic_sidebar()

侧边栏是否激活
is_active_sidebar()

小工具是否激活
is_active_widget( $widget_callback, $widget_id )

用户是否登录
is_user_logged_in()

电子邮件存在
email_exists( $email )

用户名存在
username_exists( $username )

分页页面
is_paged()

从右到左阅读
is_rtl()

附件
is_attachment()

附件是图片
wp_attachment_is_image( $post_id )

本地附件
is_local_attachment( $url )

文章类型存在
post_type_exists( $post_type )

是否主查询
is_main_query()

新的一天
is_new_day()

聚合
is_feed()

Trackback
is_trackback()

预览
is_preview()

有摘录
has_excerpt()

有指定导航菜单
has_nav_menu()

博客是否已安装
is_blog_installed()

网络的一部分 (多站点)
is_multisite()
is_main_site()
is_super_admin()

已启用插件
is_plugin_active( $path )
is_plugin_inactive( $path )
is_plugin_active_for_network( $path )
is_plugin_page()

子主题
is_child_theme()

主题支持的功能
current_theme_supports()

在定制器中预览
is_customize_preview()



关于 ·登录·管理
加载0.377 查询 15