简体   繁体   English

在Wordpress中使用子主题

[英]Using Child Themes in Wordpress

So I've been reading instructions on here and on Wordpress's official website and I'm still having an issue getting my child theme to work. 因此,我一直在这里和Wordpress的官方网站上阅读说明,但在让我的孩子主题正常工作方面仍然遇到问题。 I'm using the Agility theme and set up agility-child as the directory for my child theme. 我正在使用“敏捷性”主题,并将“敏捷性子项”设置为我的子主题的目录。 In there I have my style.css: 在这里,我有我的style.css:

/*
Theme Name:     Agility Child Theme
Theme URI:      themeforest.net/item/agility-responsive-html5-wordpress-theme/2336028
Description:    Agility Child Theme
Author:         *****
Author URI:     *****
Template:       agility
Version:        1.0.0
License:        GNU General Public License v2 or later
License URI:    http://www.gnu.org/licenses/gpl-2.0.html
*/

/* =Theme customization starts here --------------- */

Then, inside another folder (stylesheets) I have layout.css: 然后,在另一个文件夹(样式表)中,我具有layout.css:

/*
Theme Name:     Agility Child Theme
Theme URI:      themeforest.net/item/agility-responsive-html5-wordpress-theme/2336028
Description:    Agility Child Theme
Author:         *****
Author URI:     *****
Template:       agility
Version:        1.0.0
License:        GNU General Public License v2 or later
License URI:    http://www.gnu.org/licenses/gpl-2.0.html
*/

/* =Theme customization starts here --------------- */

#colophon {
    background: #fff;
    border-top: 2px solid #ddd;
}

Then, back in the main directory, functions.php: 然后,回到主目录中,functions.php:

<?php 
    add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );

    function theme_enqueue_styles() {
        wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
        wp_enqueue_style( 'parent-style', get_template_directory_uri() . 'stylesheets/layout.css' );

    } 
?> 

The child theme is active in WP but none of my CSS changes to layout.css (or the other CSS that the theme uses; style.css is basically used for nothing). 子主题在WP中处于活动状态,但是我的CSS都没有更改为layout.css(或该主题使用的其他CSS; style.css基本上什么都不用)。 Am I using functions.php incorrectly? 我是否正确使用functions.php?

get_template_directory_uri() returns the directory of the template you are using (or in other words -- the parent theme). get_template_directory_uri()返回您正在使用的模板的目录(或换句话说,父主题)。 You can use get_bloginfo( 'stylesheet_directory' ) instead. 您可以改用get_bloginfo( 'stylesheet_directory' ) This will get the stylesheet directory of the current theme. 这将获取当前主题的样式表目录。

Each of the enqueued files should also have different ids (you are using "parent-style" for both. Also, you are missing a slash on the second line. Your enqueues should probably looks something like this: 每个入队文件还应该具有不同的ID(两个都使用“父样式”。此外,第二行缺少斜杠。入队可能看起来像这样:

add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );

function theme_enqueue_styles() {

    // This will include the parent theme's stylesheet
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );

    // This will include layouts.css from the child theme's "stylesheets" directory
    wp_enqueue_style( 'layouts', get_bloginfo( 'stylesheet_directory' ) . '/stylesheets/layout.css' );
}

Reference: 参考:

http://codex.wordpress.org/Child_Themes http://codex.wordpress.org/Function_Reference/get_bloginfo http://codex.wordpress.org/Function_Reference/get_template_directory_uri http://codex.wordpress.org/Child_Themes http://codex.wordpress.org/Function_Reference/get_bloginfo http://codex.wordpress.org/Function_Reference/get_template_directory_uri

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM