首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何激活Wordpress中的子主题?

如何激活Wordpress中的子主题?
EN

WordPress Development用户
提问于 2014-06-20 03:57:53
回答 2查看 2.9K关注 0票数 0

我创建了一个新的style.css并在子主题中使用它。我在wp内容中创建了一个新文件夹,并将其命名为,并上传我创建的style.css。现在,我转到wp仪表板->外观->主题,并查看我创建的子主题。我发现了这个错误:

代码语言:javascript
复制
Broken Themes

The following themes are installed but incomplete. Themes must have a stylesheet and a     template.

Name    Description
Accesspress Lite    The parent theme is missing. Please install the "AccesspressLite" parent theme.

以下是css子主题格式:

代码语言:javascript
复制
/*
Theme Name:   Accesspress Lite
Theme URI:    http://access-keys.com/accesspresslite/
Description:  Accesspress Lite Child Theme
Author:       Yang
Author URI:   http://www.example.com
Template:     accesspress-lite
Version:      2
Tags:         blue, white, light, custom-menu, one-column, two-columns, three-columns,   left-sidebar, right-sidebar, fixed-layout, fluid-layout, custom-background, featured-image-header, sticky-post, theme-options, threaded-comments, featured-images, full-width-template, custom-header, flexible-header, responsive-layout
Text Domain:  accesspress-lite-child
*/

@import url("../accesspress-lite/style.css");
EN

回答 2

WordPress Development用户

发布于 2016-04-13 15:28:09

您需要的所有信息都可以在这里找到:https://codex.wordpress.org/Child_主题

启动和运行它的重要部分是:

确保父主题存在(在您的情况下,完整的可访问性主题)

为您的子主题创建唯一的文件夹名。

在子主题文件夹中创建一个style.css文件。

代码语言:javascript
复制
/*
Theme Name:   Your Child Theme Name
Theme URI:    http://access-keys.com/accesspresslite/
Description:  Accesspress Lite Child Theme
Author:       Your Name
Author URI:   http://www.your-child-theme.com
Template:     accesspress-lite
Version:      1.0
Tags:         blue, white, light, custom-menu, one-column, two-columns, three-columns,   left-sidebar, right-sidebar, fixed-layout, fluid-layout, custom-background, featured-image-header, sticky-post, theme-options, threaded-comments, featured-images, full-width-template, custom-header, flexible-header, responsive-layout
Text Domain:  accesspress-lite-child
*/

确保模板行与父文件夹匹配。

在子主题文件夹中创建一个functions.php文件。在该文件中,导入父主题样式。这样做,而不是样式表中的@import,可以确保满足依赖关系。

代码语言:javascript
复制
function child_theme_enqueue_styles() {
    wp_enqueue_style( 'parent-styles', get_template_directory_uri() . '/style.css' );
    wp_enqueue_style( 'child-styles',
        get_stylesheet_directory_uri() . '/style.css',
        array( 'parent-styles' )
    );
}
add_action( 'wp_enqueue_scripts', 'child_theme_enqueue_styles' );

注意,作为子主题,任何时候使用get_template_directory_uri()都是在抓取父主题目录。使用get_stylesheet_directory_uri()将为您提供子主题目录。

票数 1
EN

WordPress Development用户

发布于 2014-06-20 04:00:55

添加名称-子style.css:

代码语言:javascript
复制
/*
Theme Name: Your Theme
Version: 1.0
Author: Your Author
*/

上传到主机

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

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

复制
相关文章

相似问题

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