由于某种原因,我的子主题模板无法被识别。
我相信我遵循了正确的程序(并检查了缓存等)
/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
在子主题文件夹中新建一个文件夹,例如includes文件夹。
现在将 Divi/includes/builder/module/Blog.php 文件从父主题复制到 child-theme/includes/文件夹中。
打开子主题的 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/