【问题标题】:unable to include stylesheet for page template in child theme无法在子主题中包含页面模板的样式表
【发布时间】:2016-10-03 03:29:56
【问题描述】:

我创建了一个子主题并在子主题中创建了 page-splash.php 并为此页面创建了 page-splash.css,但不知何故我无法加载 page-splash.css page-splash.php 文件。

这是我在 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' );

}

function splash_enqueue_style() {
    wp_enqueue_style( 'page-splash', get_template_directory_uri().'/css/page-spash.css' ); 
}
add_action( 'wp_enqueue_scripts', 'splash_enqueue_style' );


?>

非常感谢您在这方面的帮助。 我究竟做错了什么?? 我在 localhost 中工作,并在一切正常后将这些文件传输到工作域。

【问题讨论】:

    标签: css wordpress themes


    【解决方案1】:

    几件事,从最简单的开始——你的 page-splash.css 文件路径中有错字。您已将其键入为 page-spash.css

    此外,可能不需要为此调用两个单独的函数。您可以像这样在一次调用中将这两种样式加入队列:

    function splash_enqueue_style() {
        wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
        if(is_page_template('page-splash.php'){
          //Path to your template.. if it's in a dir, include it before the file
          wp_enqueue_style( 'page-splash', get_template_directory_uri().'/css/page-splash.css' );
        }
    }
    add_action( 'wp_enqueue_scripts', 'splash_enqueue_style' );
    

    【讨论】:

    • 感谢您提供此信息,我会尝试一下。顺便说一句,我在让我的 page-splash.css 工作时遇到问题,因为它似乎被父主题 css 文件覆盖。我该如何解决这个问题??
    • “覆盖”是什么意思?页面中是否加载了启动样式,但其中的所有 CSS 都被覆盖了?还是根本没有加载文件?
    【解决方案2】:

    嗯,我一直在寻找答案,我已经找到了。 如果要加载所有 javascript,使用 wp_head() 似乎很重要 或 css 文件,当我这样做时它开始工作。

    【讨论】:

    • 哦是的,那也是
    猜你喜欢
    • 1970-01-01
    • 2015-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-24
    • 1970-01-01
    • 2014-01-03
    相关资源
    最近更新 更多