首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >子主题Wordpress中的Style.css和functions.php

子主题Wordpress中的Style.css和functions.php
EN

Stack Overflow用户
提问于 2017-10-12 21:08:47
回答 1查看 1.4K关注 0票数 0

我想在Wordpress中为Twenty15创建子主题,父主题中有多个样式表文件。路由是htdocs/wordpress-1/wp-content/themes/twentyfifteen-child,所以根据这里的类似问题,子节点的代码应该是:

style.css:

代码语言:javascript
复制
/*
 Theme Name:   Twenty Fifteen Child
 Theme URI:    http://localhost/wordpress-1/wp-content/themes/twentyfifteen-child/
 Description:  My first child theme, based on Twenty Fifteen
 Author:       Daniel Pataki
 Author URI:   http://danielpataki.com
 Template:     twentyfifteen
 Version:      1.0.0
 Tags:         black, green, white, light, dark, two-columns, three-columns, left-sidebar, right-sidebar, fixed-layout, responsive-layout, custom-background, custom-header, custom-menu, editor-style, featured-images, flexible-header, full-width-template, microformats, post-formats, rtl-language-support, sticky-post, theme-options, translation-ready, accessibility-ready, responsive-layout, infinite-scroll, post-slider, design, food, journal, magazine, news, photography, portfolio, clean, contemporary, dark, elegant, modern, professional, sophisticated
 Text Domain:  twenty-fifteen-child
*/

functions.php:

代码语言:javascript
复制
<?php

   function enqueue_parent_styles() {

    wp_enqueue_style( 'twentyfifteen-editor-style', get_template_directory_uri().'css/editor-style.css',array(), null, 'all' );
    wp_enqueue_style( 'twentyfifteen-ie', get_template_directory_uri().'css/ie.css',array(), null, 'all' );
    wp_enqueue_style( 'twentyfifteen-ie7', get_template_directory_uri().'css/editor-ie7.css',array(), null, 'all' );
    wp_enqueue_style( 'twentyfifteen-style', get_stylesheet_uri(), '', null, 'all' );
}


add_action( 'wp_enqueue_scripts', 'enqueue_parent_styles' );

?>

父内容(对于样式表)的路径是: htdocs/wordpress-1/wp-content/themes/twentyfifteen/css,但仍然在主题选择页面中没有子主题的预览,并且在加载主题时没有从父主题加载的css规则(二十五)。如果有人能帮我,我找不到问题所在。

EN

回答 1

Stack Overflow用户

发布于 2017-10-12 22:27:24

看起来您没有将父对象的css样式排入队列。在您的子主题的function.php文件中尝试以下内容:

代码语言:javascript
复制
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' );
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46710474

复制
相关文章

相似问题

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