2016-10-11 162 views
3

我已经创建了与我的父主题相同格式的文件结构。我的父母主题叫做Alpine,在Alpine中有一个functions.php和style.css文件。似乎没有任何额外的style.css文件。WordPress的儿童主题style.css不工作

我创建了一个名为Alpine-child的目录,并在其中创建了一个functions.php和style.css文件。

我不能工作了,为什么任何改变我做孩子的style.css尚未实现,但他们是当我在做父母的style.css同样的变化

这是我的孩子的style.css:

/* 
 
Theme Name: Alpine Child 
 
Theme URI: http://www.creative-ispiration.com/wp/alpine/ 
 
Description: My first child theme, based on Alpine 
 
Author:  MilkshakeThemes 
 
Author URI: http://themeforest.net/user/milkshakethemes 
 
Template:  Alpine 
 
Version:  1.0.0 
 
Tags: one-column, two-columns, right-sidebar, fluid-layout, custom-menu, editor-style, featured-images, post-formats, rtl$ 
 
Text Domain: alpine-child 
 
*/

这是我的孩子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'); 
 
} 
 
?>

+0

你能分享一个链接到你的项目? – Jrod

+0

我目前在AWS EC2实例上托管网站。我一直在通过SSH编辑网站。这是当前的发展地址:http://ec2-52-211-25-124.eu-west-1.compute.amazonaws.com/ –

回答

5

看看你的<head>标签。更重要的是看你的样式表的顺序。

首先添加您的孩子主题的样式,然后添加父主题的所有样式。这将导致父主题中的样式覆盖您的子主题样式。

您可以通过使用第三个参数add_action来更改my_theme_enqueue_styles函数在父项之后运行的优先级。这会将您的子主题样式排在最后,并允许CSS按预期工作。

<?php 
add_action('wp_enqueue_scripts', 'my_theme_enqueue_styles', 11); 
function my_theme_enqueue_styles() { 
    wp_enqueue_style('child-style', get_stylesheet_uri()); 
} 
?> 
+0

我可以将上面的php复制到我的functions.php文件中来改变顺序吗? –

+0

@GavinReynoldson是的。我刚刚复制了您的原始代码,并为您的'add_action'调用添加了优先级。注意'add_action('wp_enqueue_scripts','my_theme_enqueue_styles',11);'现在有第三个参数是优先级。这已设置为11,因为默认优先级为10。 – Jrod

+0

我已经将上面的代码添加到了functions.php中,并且没有任何改变。当我检查'head'时,加载的最后一个文件是父类型。我完全看不到alpine-child/style.css。 –

0

您需要排队的子主题style.css所以你的功能应该是:

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

看看在documentation

+0

不幸的是,这也不起作用。我实际上已经尝试了很多变体,并试图使用@import。似乎没有任何工作。我已经向主题开发者发送了支持消息。谢谢 –

0

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