2015年2月13日 / 643次阅读
WordPress
is_home()和is_front_page()都可以用来判断WordPress网站首页,但是其功能稍有区别。
从WordPress1.5版本开始,就有is_home()这个函数。官方对其的解释如下:
This Conditional Tag checks if the blog posts index page is being displayed. This is a Boolean function, meaning it returns either TRUE or FALSE.
这句话说,is_home()函数检查blog posts index页面是否被展示,然后返回成功或者失败。什么是blog posts index页面,请见下图:
从WordPress2.5版本开始,出现了is_front_page()函数。官方对其解释如下:
This Conditional Tag checks if the main page is a posts or a Page. This is a boolean function, meaning it returns either TRUE or FALSE. It returns TRUE when the main blog page is being displayed and the Settings->Reading->Front page displays is set to "Your latest posts", or when is set to "A static page" and the "Front Page" value is the current Page being displayed.
如果设置了静态页面作为主页,此函数可以正常工作。而is_home()函数就不行了。
还是引用官方的文字:
Since WordPress 2.1, when the static front page functionality was introduced, the blog posts index and site front page have been treated as two different query contexts, with is_home() applying to the blog posts index, and is_front_page() applying to the site front page.
Be careful not to confuse the two query conditionals:
- On the site front page, is_front_page() will always return TRUE, regardless of whether the site front page displays the blog posts index or a static page.
- On the blog posts index, is_home() will always return TRUE, regardless of whether the blog posts index is displayed on the site front page or a separate page.
可以看出,只要是blog posts index页面,is_home()都返回true。is_front_page才可以用来真正判断site front site,不管首页是什么类型。
本文链接:https://www.maixj.net/wz/is_home_is_front_page-2368
《判断WordPress网站首页,用is_home()还是is_front_gage()》有2条留言
©Copyright 麦新杰 Since 2014 云上小悟独立博客版权所有 备案号:苏ICP备14045477号-1。云上小悟网站部分内容来源于网络,转载目的是为了整合信息,收藏学习,服务大家,有些转载内容也难以判断是否有侵权问题,如果侵犯了您的权益,请及时联系站长,我会立即删除。
测试一下评论功能。 [ ]