is_home()判断首页

功能:

is_home()函数用来判断当前页面是否是首页

用法:

<?php
if(is_home()){
    echo "我只会在首页显示";
}
?>

参数:

返回值:

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

示例:

<?php
if(is_home()){
    echo "我只会在首页显示";
}else
{
    echo "我只显示在非首页";
?>

相关函数:

is_front_page()

(完)

版权声明WordPress头条正在使用WordPress文章版权插件
如未注明,均为原创,转载需注明出处
本文链接地址:http://www.wptoutiao.com/functions/108.html

is_home的相关文章

判断首页的相关文章

还可以分享文章给好友:

发表评论

电子邮件地址不会被公开。 必填项已用*标注