将样式正确地排入子主题和样式表位置

时间:2017-11-09 作者:Sergi

我继承了一个没有子主题的站点,现在我们在更新内容时会遇到问题。这个主题中的所有内容都是围绕主题制作的。。。

我现在已经创建了一个子主题,但我必须将许多脚本和样式表排队,而且我做得不对。主要问题是,我在子主题目录的css文件夹中有这些自定义样式表。但是这些函数在父主题上查找这些文件,因此显然找不到它们。我应该在父css目录上上载自定义样式表吗?或者将其放在我的子主题目录中,并以不同的方式将其排队?

下面是我的功能。php on my child主题外观:

function shopkeeper_styles_child() {

    global $shopkeeper_theme_options;

    wp_enqueue_style(\'shopkeeper-foundation-app\', get_template_directory_uri() . \'/css/app.css\', array(), \'5.3.1\', \'all\' );     

    wp_enqueue_style(\'shopkeeper-animate\', get_template_directory_uri() . \'/css/animate.css\', array(), \'2.0\', \'all\' );

    wp_enqueue_style(\'shopkeeper-font-awesome\', get_template_directory_uri() . \'/inc/fonts/font-awesome/css/font-awesome.min.css\', array(), \'4.0.3\', \'all\' );
    wp_enqueue_style(\'shopkeeper-font-linea-arrows\', get_template_directory_uri() . \'/inc/fonts/linea-fonts/arrows/styles.css\', array(), \'1.0\', \'all\' );
    wp_enqueue_style(\'shopkeeper-font-linea-basic\', get_template_directory_uri() . \'/inc/fonts/linea-fonts/basic/styles.css\', array(), \'1.0\', \'all\' );
    wp_enqueue_style(\'shopkeeper-font-linea-basic_elaboration\', get_template_directory_uri() . \'/inc/fonts/linea-fonts/basic_elaboration/styles.css\', array(), \'1.0\', \'all\' );
    wp_enqueue_style(\'shopkeeper-font-linea-ecommerce\', get_template_directory_uri() . \'/inc/fonts/linea-fonts/ecommerce/styles.css\', array(), \'1.0\', \'all\' );
    wp_enqueue_style(\'shopkeeper-font-linea-music\', get_template_directory_uri() . \'/inc/fonts/linea-fonts/music/styles.css\', array(), \'1.0\', \'all\' );
    wp_enqueue_style(\'shopkeeper-font-linea-software\', get_template_directory_uri() . \'/inc/fonts/linea-fonts/software/styles.css\', array(), \'1.0\', \'all\' );
    wp_enqueue_style(\'shopkeeper-font-linea-weather\', get_template_directory_uri() . \'/inc/fonts/linea-fonts/weather/styles.css\', array(), \'1.0\', \'all\' );  
    wp_enqueue_style(\'shopkeeper-fresco\', get_template_directory_uri() . \'/css/fresco/fresco.css\', array(), \'1.3.0\', \'all\' );
    wp_enqueue_style(\'shopkeeper-idangerous-swiper\', get_template_directory_uri() . \'/css/idangerous.swiper.css\', array(), \'\', \'all\' );
    wp_enqueue_style(\'shopkeeper-owl\', get_template_directory_uri() . \'/css/owl.carousel.css\', array(), \'1.3.1\', \'all\' );
    wp_enqueue_style(\'shopkeeper-owl-theme\', get_template_directory_uri() . \'/css/owl.theme.css\', array(), \'1.3.1\', \'all\' );
    wp_enqueue_style(\'shopkeeper-offcanvas\', get_template_directory_uri() . \'/css/offcanvas.css\', array(), \'1.0\', \'all\' );
    wp_enqueue_style(\'shopkeeper-nanoscroller\', get_template_directory_uri() . \'/css/nanoscroller.css\', array(), \'0.7.6\', \'all\' );
    wp_enqueue_style(\'shopkeeper-select2\', get_template_directory_uri() . \'/css/select2.css\', array(), \'3.4.5\', \'all\' );
    wp_enqueue_style(\'shopkeeper-easyzoom\', get_template_directory_uri() . \'/css/easyzoom.css\', array(), \'1.0\', \'all\' );
    wp_enqueue_style(\'shopkeeper-defaults\', get_template_directory_uri() . \'/css/defaults.css\', array(), \'1.0\', \'all\' );
    wp_enqueue_style(\'shopkeeper-woocommerce-overwrite\', get_template_directory_uri() . \'/css/woocommerce-overwrite.css\', array(), \'1.0\', \'all\' );
    wp_enqueue_style(\'shopkeeper-top-bar\', get_template_directory_uri() . \'/css/header-topbar.css\', array(), \'1.0\', \'all\' );
    wp_enqueue_style(\'shopkeeper-headers\', get_template_directory_uri() . \'/css/headers.css\', array(), \'1.0\', \'all\' );
    wp_enqueue_style(\'shopkeeper-menus\', get_template_directory_uri() . \'/css/navigations.css\', array(), \'1.0\', \'all\' );
    wp_enqueue_style(\'shopkeeper-custom\', get_template_directory_uri() . \'/shoopkeeper-child/css/custom_artiq.css\', array(), \'1.0\', \'all\' );

    if ( isset($shopkeeper_theme_options[\'main_header_layout\']) ) {     
        if ( $shopkeeper_theme_options[\'main_header_layout\'] == "1" ) {
            wp_enqueue_style(\'shopkeeper-header-default\', get_template_directory_uri() . \'/css/header-default.css\', array(), \'1.0\', \'all\' );
        }       
        elseif ( $shopkeeper_theme_options[\'main_header_layout\'] == "2" ) {
            wp_enqueue_style(\'shopkeeper-header-centered-2menus\', get_template_directory_uri() . \'/css/header-centered-2menus.css\', array(), \'1.0\', \'all\' );
        }
        elseif ( $shopkeeper_theme_options[\'main_header_layout\'] == "3" ) {
            wp_enqueue_style(\'shopkeeper-header-centered-menu-under\', get_template_directory_uri() . \'/css/header-centered-menu-under.css\', array(), \'1.0\', \'all\' );
        }       
    }       
    else {  
        wp_enqueue_style(\'shopkeeper-header-default\', get_template_directory_uri() . \'/css/header-default.css\', array(), \'1.0\', \'all\' );    
    }

    if (isset($shopkeeper_theme_options[\'font_source\']) && ($shopkeeper_theme_options[\'font_source\'] == "2")) {
        if ( (isset($shopkeeper_theme_options[\'font_google_code\'])) && ($shopkeeper_theme_options[\'font_google_code\'] != "") ) {
            wp_enqueue_style(\'shopkeeper-font_google_code\', $shopkeeper_theme_options[\'font_google_code\'], array(), \'1.0\', \'all\' );
        }
    }

    wp_enqueue_style(\'shopkeeper-styles\', get_template_directory_uri() . \'/css/styles.css\', array(), \'1.0\', \'all\' );
    wp_enqueue_style(\'shopkeeper-responsive\', get_template_directory_uri() . \'/css/responsive.css\', array(), \'1.0\', \'all\' );

    wp_enqueue_style(\'shopkeeper-default-style\', get_stylesheet_uri());

}
add_action( \'wp_enqueue_scripts\', \'shopkeeper_styles_child\', 99 );

1 个回复
最合适的回答,由SO网友:DHL17 整理而成

使用:wp_enqueue_style( \'test\', get_stylesheet_directory_uri() . \'/css/test.css\' );

而不是get_template_directory_uri();

结束

相关推荐

Child-theme breaks site

所以,我有一个子主题,里面除了所需的CSS文件之外什么都没有。一旦我激活了这个儿童主题,我的整个网站就关闭了。最后我有两个问题:激活一个只有CSS的子主题怎么能破坏我的网站</我怎样才能回到我原来的主题</这些是网站给我的错误:Warning: require_once(/wp-content/themes/interio_child/admin/options-framework.php) [function.require-once]: 无法打开流:中没有此类文件或目录/wp-c