Life, half is memory, half is to continue.
WordPress主题常用条件标签
By Vincent. @2025.4.14
WordPress主题常用条件标签

条件标签是一种布尔数据类型,可以在您的模板文件中使用,以根据当前页面匹配的条件来更改内容的显示。

他们告诉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_home()
is_front_page()
is_front_page()

单页面

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()

Widget活跃

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()

feed

is_feed()

引用

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()
扫码分享收藏
扫码分享收藏