功能:
is_home()函数用来判断当前页面是否是首页
用法:
参数:
无
返回值:
Boolean,是首页就返回True,其他页面都返回False
所在位置:
is_home()函数包含在 wp-includes/query.php中.
源码:
/**
* Is the query for the blog homepage?
*
* This is the page which shows the time based blog content of your site.
*
* Depends on the site's "Front page displays" Reading Settings 'show_on_front' and 'page_for_posts'.
*
* If you set a static page for the front page of your site, this function will return
* true only on the page you set as the "Posts page".
*
* @see is_front_page()
*
* @since 1.5.0
*
* @global WP_Query $wp_query Global WP_Query instance.
*
* @return bool True if blog view homepage.
*/
function is_home() {
global $wp_query;
if ( ! isset( $wp_query ) ) {
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
return false;
}
return $wp_query->is_home();
}
示例:
相关函数:
感觉本站内容不错,读后有收获?小额赞助
还可以分享文章给好友: