【问题标题】:WordPress child theme not showingWordPress子主题未显示
【发布时间】:2017-03-07 02:14:51
【问题描述】:

我刚刚创建了一个子主题并激活了它。但是当我访问该页面时,它完全是空白的。

显示的是我的父主题和子主题的主题文件夹,然后下面是父 style.css 中的站点详细信息,我只是将其复制并粘贴到子样式表中。

functions.php 看起来像这样:

<?php
function my_theme_enqueue_styles() {

    $parent_style = 'parent-style';

    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' );
?>

如图所示,主题是活跃的。

如何创建子主题并使其作为父主题可见?

【问题讨论】:

  • 完全空白的页面可能是错误的结果。是WP_DEBUGtrue
  • @Andy Tschiersch。是的,它设置为 true。我之前使用二十六主题创建了子主题,wp-debug 设置为 false 并且可以正常工作。

标签: php wordpress


【解决方案1】:

您不应该只是复制父样式,最好创建一个新样式并导入父样式。您还需要将模板指定为父主题。试试这个:

/*
    Theme Name:   Sidimaag Child Theme
    Theme URI:    http://underscores.me
    Description:  Sidimaag Child Theme
    Author:       mytheme
    Author URI:   http://mytheme.co.za
    Template:     sidimaag
    Version:      1.0.0
    License:      GNU General Public License v2 or later
    License URI:  http://www.gnu.org/licenses/gpl-2.0.html
    Tags:         light, dark, two-columns, right-sidebar, responsive-layout, accessibility-ready
    Text Domain:  sidimaag
    */

然后你可以像这样使用@import 导入父级的样式:

@import url('path_to_parent_theme/style.css');

【讨论】:

  • 我做到了,是的。现在我按照您的建议使用导入而不是functions.php,但它也可以正常工作。 @import url('../sidimaag/style.css');这很有趣,因为之前,我使用相同的程序使用 216 主题创建了子主题,并且它有效,所以我真的不知道如何解决这个问题。
  • 为了在你的functions.php中加入父母的风格,在你的子functions.php文件中使用它:add_action('wp_enqueue_scripts','sidimaag_child_theme_enqueue_styles');函数 sidimaag_child_theme_enqueue_styles() { wp_enqueue_style( 'sidimaag', get_template_directory_uri() . '/style.css' ); } 如果您可以提供对 WP 的访问权限,我可以为您提供帮助。
  • @I.T.我希望我能给你访问权限。我正在本地主机上工作。
  • 好的,不用担心。您是否按照我之前的建议在您孩子的 style.css 中添加了模板:sidimaag?创建子主题非常简单,子主题应该只在 style.css 文件中可见。请检查您的路径并查看此视频:youtube.com/watch?v=wEYSqEBZHRE
【解决方案2】:

为了挽救您的生命,只需安装 themify 插件。 这非常简单。你安装插件。去: 外观 -> 主题 当您看到您的主题时,将鼠标悬停在它上面,您将看到主题详细信息。单击它,然后查找名为:创建子主题..命名您的主题,单击确定...和 ​​vuala!!! 的按钮!

【讨论】:

    猜你喜欢
    • 2015-08-07
    • 1970-01-01
    • 2020-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-15
    相关资源
    最近更新 更多