我正在制作一个“生长极小”主题的简单子主题。
我创建了一个文件夹,grow-minimal-child并添加了functions.php和style.css:
functions.php:
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:
/*
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.php在Grow-minimal文件夹中的内容:
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哪里出错了(或者更有可能的是,我在哪里没有更新或链接到父级)?
发布于 2018-10-02 04:40:04
您试图作为父级生长极小使用的主题是成长主题的子主题。如果不编写自定义代码解决方案,就不可能创建另一个子主题的子主题。
在您的代码中,这两行只需执行两次相同的操作:
wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
wp_enqueue_style('thinkup-style', get_template_directory_uri() . '/style.css');它们为父主题Grow的样式表排队。“增长最小”主题被忽略。这个问题提供了更多关于孙子主题问题的上下文。
在这种情况下,最佳实践是简单地将您的自定义样式或模板代码直接添加到现成的子主题(增长最小),有效地将其转换为自定义主题。您仍然可以在未修改的父主题上应用任何更新,而不会丢失自定义。
https://wordpress.stackexchange.com/questions/315663
复制相似问题