视频:https://www.bilibili.com/video/BV1yp42117o4/
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() 的用法也就不一样。
------------
分类列表页:使用taxonomy.php,不会用category.php
taxonomy-{taxonomy}-{term}.php
taxonomy-{taxonomy}.php --- procate / casecate
taxonomy.php
archive.php
index.php
---------
系统默认分类:
category-{slug}.php
category-{id}.php
category.php
archive.php
index.php
--------
详情页:
single-{post-type}.php -- products / case
single.php
singular.php
index.php
---------------------
一般页面:
custom template file
– The page template assigned to the page. See get_page_templates()
.page-{slug}.php
– If the page slug is recent-news
, WordPress will look to use page-recent-news.php
.page-{id}.php
– If the page ID is 6, WordPress will look to use page-6.php
.page.php
singular.php
index.php
page template是这样生成的:
<?php /* Template Name: Example Template */ ?>
------------------
如何知道wordpress当前页面使用了哪个模板文件?
在footer.php里加以下代码即可:
<?php
if(is_user_logged_in()){
global $template;
echo '<p style="background:red;color:#fff;text-align:center">'.basename($template).'</p>';
}
?>