检查页面类型:
function get_author_bio ($content=\'\'){
if ( ! is_single() ) // not a blog post, stop immediately
{
return $content;
}
global $post; // continue with regular work
了解这些检查函数的最简单方法是查看函数
get_body_class()
. 以下是最重要的:
is_rtl()
is_front_page()
is_home()
is_archive()
is_date()
is_search()
is_paged()
is_attachment()
is_404()
is_single()
is_page()
is_singular() // same as is_page() and is_single()
is_attachment()
is_archive()
is_post_type_archive()
is_author()
is_category()
is_tag()
is_tax()
is_user_logged_in()
is_admin_bar_showing()
您甚至可以将它们组合在一起:
// search results, not the first page
if ( is_search() and is_paged() )
// attachment and user has probably a profile
if ( is_attachment() and is_user_logged_in() )
其中一些函数接受参数以限制结果:
// contact page only
if ( is_page( \'contact\' ) )
// this post was written by the tooth fairy
if ( is_author( \'tooth-fairy\' ) )