当子页面未定义时,Wordpress模板的层次结构


Wordpress template hierarchy when subpages not defined

示例站点(mysite.com)和使用wordpress定义为mysite.com/mypage的页面

本页经过模板page-mypage.php。现在,当我运行mysite.com/mypage/somechild,其中somechild页没有与wordpress定义。这将导致未找到错误(404)。

如何使mysite.com/mypage/*/*通过模板page-mypage.php ?

wordpress不是slug基础模板,请检查

https://developer.wordpress.org/files/2014/10/template-hierarchy.png

假设您有一个名为mypage的页面,它将使用if exists

custom-template-you-define.php //if doesn't exist it will look for 
page-[slug].php // if doesn't exist it will look for 
page-[id].php // if doesn't exist it will look for 
page.php // if doesn't exist it will look for 
singular.php //if doesn't exist it will look for 
index.php //if doesn't exist White Screen

如果您创建了另一个名为somechild的页面,则将此方法应用于该页

您也必须为子页面选择相同的页面模板。