关于小悟志网站地图归档友情链接联系Feed

云上小悟 + 

判断WordPress网站首页,用is_home()还是is_front_gage()

网站建设
2015年2月13日 / 525次阅读
标签:WordPress

拍拍贷

文章《判断WordPress网站首页,用is_home()还是is_front_gage()》的特色图片

is_home()和is_front_page()都可以用来判断WordPress网站首页,但是其功能稍有区别。

is_home()

从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页面,请见下图:

blog-posts-index-page,wordpress最新文章首页

is_front_page()

从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:

  1. 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.
  2. 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,不管首页是什么类型。

本文链接:http://www.maixj.net/wz/is_home_is_front_page-2368
云上小悟 麦新杰(QQ:1093023102)

-- (*^-^*) --

相关文章

评论是美德

《判断WordPress网站首页,用is_home()还是is_front_gage()》有2条评论

无力满足评论实名制,评论对非实名注册用户关闭,有事QQ:1093023102.


前一篇:
后一篇:

栏目精选


©Copyright 麦新杰 Since 2014 云上小悟独立博客版权所有 备案号苏ICP备14045477号-1

网站二维码
拍拍贷
go to top