php - 如何让子主题模块模板覆盖主模块模板

标签 php wordpress wordpress-theming divi

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

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

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

应该替换

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

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

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

I have tested editing the main file and this works immediately every time.

非常感谢任何建议。

干杯


编辑

下面的内容应该根据 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' );

最佳答案

还有其他一些步骤https://intercom.help/elegantthemes/en/articles/4532734-moving-blog-module-in-child-theme

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

  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';与 $this->vb_support = 'off';

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

  • 最后,将以下代码添加到子主题文件夹中的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' );
    
    

    关于php - 如何让子主题模块模板覆盖主模块模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63912727/

    相关文章:

    php - 希伯来语或英语的正则表达式

    javascript - 如何使用JS使用更新值自动更新第二个文本框

    php - 调用未定义函数 odbc_connect() centos 7

    wordpress - 如何使用Bootstrap 4使文本环绕图像而没有 float ?

    Javascript 问题 - setTimeout?

    mysql - 在 WordPress 中使用 MySQL 查询检索小部件数据

    php - 从php获取mysql等待超时

    asp.net - wordpress 和 asp.net 在一起

    jquery - 在 WordPress 主题选项页面中排队 jquery-ui 元素

    javascript - WordPress:在 JavaScript 中获取 block ID