简体   繁体   English

为WordPress主题应用两个样式表

[英]Applying two stylesheets for WordPress Theme

I would like to add two stylesheets to my WordPress theme. 我想在我的WordPress主题中添加两个样式表。 I would like to have one style sheet for my home page and another for my about page. 我想为我的主页提供一个样式表,为我的About页面提供另一个样式表。 The reason for this is I would like to apply different styles to my header and footer for these pages. 原因是我想对这些页面的页眉和页脚应用不同的样式。

I tried the code below within function.php but of course it did not work. 我在function.php中尝试了下面的代码,但是当然没有用。

wp_register_script ('add-about-css', get_stylesheet_directory_uri('about'). '/about.css' );

wp_enqueue_script('add-about-css');

add_action('wp_enqueue_scripts');

First of all get_stylesheet_directory_uri does not accept any parameter. 首先,get_stylesheet_directory_uri不接受任何参数。

Next 下一个

<?php if (is_page('$your_page_name/id/slug')) { ?>
<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/about.css" type="text/css">
<?php }; ?>

Put this code in your header after linking to your default stylesheet. 链接到默认样式表后,将此代码放在标题中。 This will overwrite default styles with your new-style (for header, footer or whatever you defined). 这将用您的新样式(用于页眉,页脚或您定义的任何样式)覆盖默认样式。 This is the case when you have same header with different style. 当您具有不同样式的相同标题时,就是这种情况。

Alternately, if you are having two separate headers, then you can use 或者,如果您有两个单独的标题,则可以使用

<?php get_header('custom') ?>

to load header-custom.php (if found else load default header.php) and custom styles for this can either be placed in style.css or can be included separately like 加载header-custom.php(如果找到,则加载默认header.php),为此的自定义样式可以放置在style.css中,也可以单独包含,例如

add_action('wp_enqueue_scripts','my_function');
function my_function(){
wp_enqueue_style('my-custom-style', get_template_directory_uri() . '/my-custom-style.css');   
}

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

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