【问题标题】:Wordpress - child theme won't complete installationWordpress - 子主题无法完成安装
【发布时间】:2017-10-05 14:15:02
【问题描述】:

我正在使用 HTML5 Blank 作为父主题的子主题。我以前使用过这个没有任何问题,但由于某种原因,我现在在我的主题页面上收到以下错误 -

破碎的主题 以下主题已安装但不完整。 名称 说明
HTML5 空白子主题 缺少父主题。请安装“html5blank”父主题。

这是我文件夹中的 -

style.css

/*
 Theme Name:   HTML5 Blank Child Theme
 Description:  A child theme of the HTML5 Blank WordPress theme
 Author:       Mike Whitehead
 Template:     html5blank
 Version:      1.0.0
*/

我已经尝试了许多不同的变体 - 也复制了官方的 wordpress 指南。上面的措辞在我的上一个项目中对我有用,所以不知道为什么它现在不起作用。

这是我的函数文件 -

functions.php

<?php
function my_theme_enqueue_styles() {

    $parent_style = 'html5blank-style'; // This is 'twentyfifteen-style' for the Twenty Fifteen theme.

    wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
    wp_enqueue_style( 'child-style',
        get_stylesheet_directory_uri() . '/style.css',
        array( $parent_style ),
        wp_get_theme()->get('Version')
    );
}
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
?>

不知道为什么这不起作用。任何帮助将不胜感激。

【问题讨论】:

  • 父子主题目录的名称是什么?这可能是命名约定的问题。
  • 你的父主题是否有这个文件夹名称:html5blank
  • @Dedering 父目录名是 html5blank-stable 这会改变吗?
  • @AkshayShah 见上面的答案
  • 请看我的回答。子主题的“模板”标签应与父主题的文件夹名称匹配。

标签: php wordpress html


【解决方案1】:

子主题 style.css 'Template' 标签应与父主题文件夹名称匹配,例如。

/*
 Theme Name:   HTML5 Blank Child Theme
 Description:  A child theme of the HTML5 Blank WordPress theme
 Author:       Mike Whitehead
 Template:     html5blank-stable
 Version:      1.0.0
*/

根据儿童主题的 WordPress Codex 页面 - https://codex.wordpress.org/Child_Themes

“模板行对应于父主题的目录名称。我们示例中的父主题是二十五主题,因此模板将是二十五。您可能正在使用不同的主题,因此请相应调整。”

【讨论】:

    【解决方案2】:

    获取父主题的文本域并将其作为子主题的模板名称。假设您的 Parent 主题的 Style.css 标题是这样的......

    /*
     Theme Name:   HTML5 Parent Theme
     Description:  A HTML5 Blank Parent WordPress theme
     Author:       Mike Whitehead
     Text domain: html5blank
     Version:      1.0.0
    */
    

    然后你可以像这样在你的子主题中使用这个文本域名..

    /*
     Theme Name:   HTML5 Blank Child Theme
     Description:  A child theme of the HTML5 Blank WordPress theme
     Author:       Mike Whitehead
     Template:     html5blank
     Version:      1.0.0
    */
    

    【讨论】:

    • 不正确...子主题“模板名称”应与父主题的文件夹名称匹配...
    猜你喜欢
    • 2012-09-12
    • 1970-01-01
    • 2016-08-02
    • 1970-01-01
    • 2019-06-14
    • 1970-01-01
    • 2016-10-20
    • 2017-11-08
    相关资源
    最近更新 更多