子主题仅使用index.php而不是从父主题继承模板

时间:2016-01-03 23:30:12

标签: php wordpress wordpress-theming

我有一个我已经开发并想要制作儿童主题的主题。我的wp-content/themes目录看起来像这样:

parenttheme
    |- style.css
    |- functions.php
    |- index.php
    |- page-example.php
childtheme
    |- style.css
    |- functions.php
    |- index.php

问题是page-example.php使用childtheme在网站中加载时,只使用了childtheme/index.php

我可以在childtheme/index.php中执行类似的操作:

echo body_class(); // class="page page-id-24 page-template page-template-page-example page-template-page-example-php logged-in admin-bar no-customize-support"

正确查找的类(page-template-page-example),但它没有使用parenttheme模板文件。

到目前为止我的hacky解决方案是添加一个只包含childtheme/page-example.php的{​​{1}}文件,但似乎我不应该这样做。

我发现这篇帖子,这似乎是我的确切问题,但没有答案...... Can I create new page.php on child theme in wordpress?

我已经阅读了WordPress子主题代码,并且用尽了我能想到的有关该主题的所有其他资源。有没有人以前处理过这个问题?

我使用WordPress 4.4和多站点,如果重要的话。

有问题的完整模板:

require('parenttheme/page-example.php')

我还有十几个其他模板也没有工作。

1 个答案:

答案 0 :(得分:2)

这是我在评论中谈到的消息。这显示在子主题的主题页面上:enter image description here

如果没有,您可能没有正确设置您的孩子主题。确保您的子主题style.css文件在顶部有这样的内容:

/*
Theme Name:         Boston
Theme URI:          http://www.phoenixwebdev.com.au
Description:        Responsive Boston template child
Version:            1.0
Author:             James Jones
Author URI:         http://www.phoenixwebdev.com.au
Template:           boston
Tags:               modern, two-columns, threaded-comments, custom-menu, translation-ready
*/ 

将儿童主题的重要部分作为“模板”条目。

您可以尝试的其他事项:

wp-includes\template.php中查看功能load_template()locate_template()。使用print_r()输出这些函数在页面加载时正在执行的操作,以尝试帮助您诊断正在加载的文件及其出错的位置。

get_page_template()中输出函数functions.php,以查看WordPress认为它正在输出的内容。这也可能对你有所帮助。

祝你好运,或希望别人能带来更多亮点。

相关问题