简体   繁体   English

html5blank的Wordpress儿童主题

[英]Wordpress Child theme for html5blank

I'm having so much trouble setting up a child theme of the html5blank theme. 我在设置html5blank主题的子主题时遇到了很多麻烦。 To the point where I'm doing a fresh install of the parent theme and starting from scratch - and writing this post as I go through it! 到目前为止,我正在重新安装父主题,并从头开始-在撰写本文时写这篇文章! Basically upon creating the child them I now need to load my custom /css/main.css file - and it's not having it! 基本上,在创建子对象之后,我现在需要加载我的自定义/css/main.css文件-它没有文件! Description of setup process follows: 设置过程的说明如下:

I've dropped a freshly downloaded html5blank folder into /themes/ and activated it. 我将一个新下载的html5blank文件夹拖放到/ themes /中并激活了它。 After that I have created another folder within /themes/ called "html5blank-child". 之后,我在/ themes /中创建了另一个文件夹“ html5blank-child”。 Within that I've created a new, blank style.css and functions.php. 在其中,我创建了一个新的空白style.css和functions.php。

Within style.css I have the following: style.css中,我具有以下内容:

/*
 Theme Name:   HTML5 Blank Child
 Theme URI:    http://example.com/twenty-fifteen-child/
 Description:  HTML5 Blank Child Theme
 Author:       My Name
 Author URI:   http://myportfolio.com
 Template:     html5blank
 Version:      1.0.0
 License:      GNU General Public License v2 or later
 License URI:  http://www.gnu.org/licenses/gpl-2.0.html
 Tags:         light, dark, two-columns, right-sidebar, responsive-layout, accessibility-ready
 Text Domain:  html5blank-child
*/

And within functions.php I have: functions.php中,我有:

<?php
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
function my_theme_enqueue_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}
?>

With all that done, I active my child theme. 完成所有这些工作后,我活跃了我的孩子主题。 With all that done, everything still appears to be working. 完成所有这些操作后,一切似乎仍在工作。 As I've created static templates of the website, I drop my 'img', 'css', 'font' and 'js' folders into the html5blank-child. 在创建网站的静态模板后,将“ img”,“ css”,“ font”和“ js”文件夹放入html5blank-child。

Now my 'actual' CSS file has a path of: html5blank-child/css/main.css 现在,我的“实际” CSS文件具有以下路径: html5blank-child / css / main.css

I need to load this file in. I was told to adjust my functions.php CSS path to: /css/main.css ...but it won't load the file at all. 我需要加载此文件。有人告诉我将我的functions.php CSS路径调整为:/css/main.css ...,但它根本不会加载该文件。 I've also tried using get_stylesheet_directory_uri() instead of get_template_directory_uri() as was advised by someone else but no luck! 我也尝试过使用get_stylesheet_directory_uri()代替get_template_directory_uri()正如其他人建议的那样,但是没有运气!

The reason I've documented the process like this is, last time I got to this point if I went to access the Wordpress admin using http://localhost:8888/websitename/admin it won't redirect to wp-admin like it normally does. 我记录这样的过程的原因是,上一次到此为止,如果我使用http://localhost:8888/websitename/admin访问Wordpress http://localhost:8888/websitename/admin ,它将不会像这样重定向到wp-admin通常会。 Also when I went to save a post, I've get a blank page. 另外,当我去保存帖子时,我得到了一个空白页。 Thankfully that isn't happening this time so I guess it's a good (better) start but now I need to get my files loaded in. 幸运的是,这次没有发生,所以我想这是一个很好的开始,但是现在我需要加载我的文件。

Hope someone can help! 希望有人能帮忙! :) :)

You need to import the style.css from main theme first inside the style.css of the child theme. 您需要首先从主要主题中的子主题的style.css中导入style.css。

Use @import to import the css file first. 首先使用@import导入css文件。

Also remove the parent-style from functions.php of child theme and then include your html5blank-child/css/main.css like the following given, 还要从子主题的functions.php中删除父样式,然后像下面给出的那样包含html5blank-child / css / main.css,

add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
function my_theme_enqueue_styles() {
    wp_enqueue_style( 'child-main', get_stylesheet_directory_uri() . '/css/main.css' );
}

Load the parent themes style.css first, then load your child themes CSS like this: 首先加载父主题style.css,然后加载您的子主题CSS,如下所示:

add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
function my_theme_enqueue_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
    wp_enqueue_style( 'child-main', get_stylesheet_directory_uri() . '/css/main.css', array('parent-style') );
}

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

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