WordPress子主题,包含includes文件

我正在使用AMPPS作为本地主机的本地计算机上进行WordPress设置。使用Delta主题, 我创建了一个子主题(delta2-child)。初始设置效果很好。但是, 我需要更改包含文件夹中名为home-slider.php的文件。

原始文件的位置:

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

如果我将home-slider文件移动到Child Theme文件夹[delta2-child \ includes \ home-slider.php], 则该主题仍将使用Parent Themes home-slider文件。

如果我将以下内容添加到CT的functions.php文件中:

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

我收到以下错误:

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

有知识的人能告诉我如何参考家用滑块文件而不会产生上述错误吗?


#1


你可以使用get_template_part函数

更改

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

to

get_template_part('includes/home-slider');

#2


不要将home-slider.php文件从父主题移动到子主题。将此文件复制到子主题文件夹中, 然后在该文件中执行你想做的事情。它将覆盖父文件的功能。

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


#3


摩门是正确的。 OP, 请标记他为正确答案。唯一的错误是他忽略了用’包围文件路径。

get_template_part(‘includes / home-slider’);

来源:

https://www.srcmini02.com/64243.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_37490.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?