首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >子主题不使用父主题css/样式/格式?

子主题不使用父主题css/样式/格式?
EN

WordPress Development用户
提问于 2018-10-01 19:25:44
回答 1查看 199关注 0票数 1

我正在制作一个“生长极小”主题的简单子主题。

我创建了一个文件夹,grow-minimal-child并添加了functions.phpstyle.css

functions.php

代码语言:javascript
复制
function my_theme_enqueue_styles() {

    $parent_style = 'grow-thinkup-style-minimal'; // This is 'twentyfifteen-style' for the Twenty Fifteen theme.
    wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
    wp_enqueue_style('thinkup-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' );

style.css

代码语言:javascript
复制
/*
Theme Name: Grow Minimal Child
Theme URI: https://www.thinkupthemes.com/free/grow/
Author: Think Up Themes
Author URI: https://www.thinkupthemes.com
Description: Created for customizing...
Template: grow
Version: 1.0.1
License: GNU General Public License v2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Tags: one-column, two-columns, three-columns, right-sidebar, left-sidebar, custom-header, custom-menu, full-width-template, theme-options, threaded-comments, editor-style, featured-images, featured-image-header, post-formats, sticky-post, translation-ready, flexible-header, custom-background, grid-layout, footer-widgets, blog, e-commerce, portfolio, rtl-language-support
Text Domain: grow-minimal-child
*/

所以,如果你看到我没有真的添加任何CSS。然而,现在当我激活这个子主题,并访问该网站,它看起来有点不同。就好像父CSS完全被忽略了一样。我还尝试使用$parent_style = 'parent-style'$parent_style = 'thinkup-style'

下面是functions.phpGrow-minimal文件夹中的内容:

代码语言:javascript
复制
function grow_thinkup_child_frontscripts() {

    wp_enqueue_style( 'thinkup-style', get_template_directory_uri() . '/style.css', array( 'thinkup-bootstrap' ) );
    wp_enqueue_style( 'grow-thinkup-style-minimal', get_stylesheet_directory_uri() . '/style.css', array( 'thinkup-style' ), wp_get_theme()->get('Version') );
}
add_action( 'wp_enqueue_scripts', 'grow_thinkup_child_frontscripts' );

当我将我的主题改为Grow Minimal时,这个站点看上去和预期的一样。

css哪里出错了(或者更有可能的是,我在哪里没有更新或链接到父级)?

EN

回答 1

WordPress Development用户

回答已采纳

发布于 2018-10-02 04:40:04

您试图作为父级生长极小使用的主题是成长主题的子主题。如果不编写自定义代码解决方案,就不可能创建另一个子主题的子主题。

在您的代码中,这两行只需执行两次相同的操作:

代码语言:javascript
复制
wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
wp_enqueue_style('thinkup-style', get_template_directory_uri() . '/style.css');

它们为父主题Grow的样式表排队。“增长最小”主题被忽略。这个问题提供了更多关于孙子主题问题的上下文。

在这种情况下,最佳实践是简单地将您的自定义样式或模板代码直接添加到现成的子主题(增长最小),有效地将其转换为自定义主题。您仍然可以在未修改的父主题上应用任何更新,而不会丢失自定义。

票数 2
EN
页面原文内容由WordPress Development提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://wordpress.stackexchange.com/questions/315663

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档