WordPress子主题包括包含文件

3

我正在使用 AMPPS 作为本地主机,在我的计算机上设置一个 WordPress。我使用 Delta 主题创建了一个子主题(delta2-child)。最初的设置运行良好。然而,我需要更改一个名为 home-slider.php 的 includes 文件夹中的文件。

原始文件位置:

c:\Program Files (x86)\Ampps\www\armstrong\wp-content\themes\delta\includes\home-slider.php

子主题文件的位置:

c:\Program Files (x86)\Ampps\www\armstrong\wp-content\themes\delta2-child\includes\home-slider.php

如果我将主页滑块文件移动到子主题文件夹 [delta2-child\includes\home-slider.php],主题仍然使用父主题的主页滑块文件。

如果我在子主题的 functions.php 文件中添加以下内容:

require_once( get_stylesheet_directory_uri() . "/includes/home-slider.php" ); */

I get the following error:

Warning: require_once(C:\Program Files (x86)\Ampps\www\armstrong/wp-content/themes/delta/includes/home-slider.php) [function.require-once]: failed to open stream: No such file or directory in C:\Program Files (x86)\Ampps\www\armstrong\wp-content\themes\delta2-child\header.php on line 87

Fatal error: require_once() [function.require]: Failed opening required 'C:\Program Files (x86)\Ampps\www\armstrong/wp-content/themes/delta/includes/home-slider.php' (include_path='.;C:\php\pear') in C:\Program Files (x86)\Ampps\www\armstrong\wp-content\themes\delta2-child\header.php on line 87

有没有了解的人可以告诉我如何引用home-slider文件而不会产生上述错误。

3个回答

5
你可以使用get_template_part函数。
更改:
require_once( get_stylesheet_directory_uri() . "/includes/home-slider.php" );

为了

get_template_part('includes/home-slider');

不要使用 get_stylesheet_directory_uri 来包含或需要文件,而是使用 get_stylesheet_directory - user3934058

0

不要将home-slider.php文件从父主题移动到子主题。将此文件复制到您的子主题文件夹中,然后在此文件中进行所需操作。它将覆盖父文件的功能。

有关子主题的更多信息,请阅读:codex.wordpress.org/child-theme


0

Mo'men的回答是正确的。楼主请将他标记为正确答案。唯一的错误是他忽略了用 ' 包围文件路径。

get_template_part('includes/home-slider');


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接