wordpress技术文章

wordpress模板文件的层级结构 wp-hierarchy,判断wordpress首页

日期:2020-04-25 阅读:819

https://developer.wordpress.org/themes/basics/template-hierarchy/

如果上面链接打不开,请看这个>

首页的规则:

front-page.php  – Used for both “your latest posts” or “a static page” as set in the front page displays section of Settings → Reading.
home.php  – If WordPress cannot find front-page.php and “your latest posts” is set in the front page displays section, it will look for home.php. Additionally, WordPress will look for this file when the posts page is set in the front page displays section.
page.php  – When “front page” is set in the front page displays section.
index.php  – When “your latest posts” is set in the front page displays section but home.php does not exist or when front page is set but page.php does not exist.

上面意思。front-page.php是首页。

但是home.php 并不一定是首页。因为它只适用于post之类的首页。如果首页指定为page。则不是这个。只能是front-page

所以 is_home() 和 is_front_page() 的用法也就不一样。