【问题标题】:WordPress Child Theme including includes filesWordPress子主题包括包含文件
【发布时间】:2019-01-15 14:25:48
【问题描述】:

我正在本地计算机上使用 AMPPS 作为我的 localhost 进行 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 文件移动到子主题文件夹 [delta2-child\includes\home-slider.php],主题仍然使用父主题的 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

任何有知识的人都可以告诉我如何在不产生上述错误的情况下引用主滑块文件。

【问题讨论】:

    标签: php jquery css wordpress wordpress-theming


    【解决方案1】:

    你可以使用get_template_part函数

    改变

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

    get_template_part('includes/home-slider');
    

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        【解决方案3】:

        Mo'men 上面说的没错。 OP请将他标记为正确答案。唯一的错误是他忽略了用 ' 包围文件路径。

        get_template_part('includes/home-slider');

        【讨论】:

          猜你喜欢
          • 2013-11-10
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-10-26
          • 2013-02-03
          • 1970-01-01
          • 2013-07-11
          • 1970-01-01
          相关资源
          最近更新 更多