【问题标题】:Wordpress template hierarchy when subpages not defined未定义子页面时的 Wordpress 模板层次结构
【发布时间】:2015-09-11 01:07:02
【问题描述】:

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

此页面通过模板page-mypage.php。现在,当我运行 mysite.com/mypage/somechild 时,somechild 页面没有用 wordpress 定义。这会导致未找到错误(404)。

我如何让mysite.com/mypage/*/* 通过模板page-mypage.php

【问题讨论】:

    标签: php wordpress apache .htaccess wordpress-theming


    【解决方案1】:

    wordpress 不是 slug base 模板,请检查

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

    假设你有一个名为 mypage 的页面,如果存在就会使用它

    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 的页面分配为子页面,则相同的方法适用于该页面。

    【讨论】:

      【解决方案2】:

      您也必须为子页面选择相同的页面模板。确保你已经这样做了。

      【讨论】:

      • 好的。会有很多随机子页面,例如 mypage/child-a mypage/child-abcx 我该如何处理?
      猜你喜欢
      • 2017-12-29
      • 1970-01-01
      • 1970-01-01
      • 2023-03-19
      • 1970-01-01
      • 1970-01-01
      • 2017-08-23
      • 1970-01-01
      • 2018-06-05
      相关资源
      最近更新 更多