【问题标题】:Style.css & functions.php in child theme Wordpress子主题 Wordpress 中的 Style.css 和 functions.php
【发布时间】:2018-03-24 10:37:05
【问题描述】:

我想在 Wordpress 中为二十五岁创建一个子主题,其中包含来自父主题的多个样式表文件。 路线是 htdocs/wordpress-1/wp-content/themes/twentyfifteen-child 所以根据这里的类似问题,孩子的代码应该是:

style.css:

/*
 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:

<?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 规则。我找不到问题,如果有人可以帮助我..

【问题讨论】:

标签: wordpress themes


【解决方案1】:

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

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' );

【讨论】:

    猜你喜欢
    • 2017-03-04
    • 2020-09-13
    • 2017-02-19
    • 2021-01-16
    • 1970-01-01
    • 2019-05-27
    • 1970-01-01
    • 1970-01-01
    • 2017-01-16
    相关资源
    最近更新 更多