【问题标题】:How to get child theme module templates to override main module template如何获取子主题模块模板以覆盖主模块模板
【发布时间】:2020-09-16 03:34:59
【问题描述】:

由于某种原因,我的子主题模板无法识别。

我相信我遵循了正确的程序(并检查了缓存等)

/wp-content/themes/divi-child/includes/builder/module/Blog.php

应该替换

/wp-content/themes/Divi/includes/builder/module/Blog.php

(相同的路径和相同的文件,略有更新)

子主题模块模板无法识别(更改子主题模板无效)

我已经测试过编辑主文件,并且每次都可以立即使用 时间。

非常感谢任何建议。

干杯


编辑

根据 Divi,以下内容应该可以工作,但是当我尝试时它会破坏网站。

显然,仅仅将模块复制到子主题中是不够的。该文件需要复制。然后将文件复制到 child-theme/custom-modules/Blog.php。在functions.php文件底部添加以下代码后:

function divi_custom_blog_module() {
get_template_part( '/custom-modules/Blog' );
$myblog = new custom_ET_Builder_Module_Blog();
remove_shortcode( 'et_pb_blog' );
add_shortcode( 'et_pb_blog', array( $myblog, '_render' ) );
}
add_action( 'et_builder_ready', 'divi_custom_blog_module' );

【问题讨论】:

  • 我明白了,在指南中 - 他们说你需要把你的博客模板文件放到:/wp-content/themes/divi-child/custom-modules/。稍后将代码添加到您的子主题的functions.php 文件的底部。那是你做的吗?

标签: php wordpress wordpress-theming divi


【解决方案1】:

还有几个步骤https://intercom.help/elegantthemes/en/articles/4532734-moving-blog-module-in-child-theme

  1. 在子主题文件夹中新建一个文件夹,例如包含文件夹。

  2. 现在将 Divi/includes/builder/module/Blog.php 文件从父主题复制到 child-theme/includes/ 文件夹中。

  3. 打开您的子主题的 Blog.php 文件并替换这一行(在最顶部):

    require_once 'helpers/Overlay.php';
        
    class ET_Builder_Module_Blog extends ET_Builder_Module_Type_PostBased {

与:

    get_template_part( '/includes/builder/module/helpers/Overlay.php' );
    
    class custom_ET_Builder_Module_Blog extends ET_Builder_Module_Type_PostBased {

替换:$this->vb_support = 'on'; with $this->vb_support = 'off';

从底部删除这一行:new ET_Builder_Module_Blog();

  1. 最后,将以下代码添加到您的子主题文件夹中的functions.php文件中:

/*================================================

#Load custom Blog  Module

================================================*/

function divi_custom_blog_module() {

    get_template_part( '/includes/Blog' );

    $myblog = new custom_ET_Builder_Module_Blog();

    remove_shortcode( 'et_pb_blog' );

    add_shortcode( 'et_pb_blog', array( $myblog, '_render' ) );

}

add_action( 'et_builder_ready', 'divi_custom_blog_module' );

【讨论】:

    【解决方案2】:

    我之前遇到过类似的问题。我认为-也许博客模板被“父亲主题”文件夹中的另一个文件调用,例如:

    $url = dirname(__FILE__)."/includes/builder/module/Blog.php";
    

    这将导致问题。解决这个问题有两种方法:

    #1:找到并编辑被称为博客模板的文件(不推荐)

    #2:找到并复制将博客模板调用到您的子主题的文件(您可以先尝试使用 index.php、content.php 或 single.php)(推荐)

    【讨论】:

    • 显然还有额外的步骤 - 见下文:
    猜你喜欢
    • 2018-02-20
    • 1970-01-01
    • 1970-01-01
    • 2015-04-03
    • 2012-04-17
    • 2016-05-18
    • 1970-01-01
    • 2016-06-14
    • 1970-01-01
    相关资源
    最近更新 更多