如何使用WordPress链接多个CSS文件

Rym*_*mes 4 css php wordpress hyperlink

我知道要链接style.css你使用的WordPress主文件:

<link href="<?php bloginfo('stylesheet_url');?>"rel="stylesheet" type="text/css"/>
Run Code Online (Sandbox Code Playgroud)

但是我有很多CSS文件需要链接到主要的PHP文件,如滑块,图片框等...

我不太确定我会怎么做,因为<?php bloginfo('stylesheet_url');?>命名的样式表styles.css和我的其他样式表的唯一作品都有不同的名称.

有谁知道我怎么能把它们全部涂在里面?

Jay*_*Jay 10

只需将所有样式表放在一个目录中即可wp-content\themes\twentyeleven\css.只需将下面的代码放在下面即可链接所有这些样式表.

<link rel="stylesheet" type="text/css" href="<?php echo get_template_directory_uri(); ?>/css/style1.css" />
<link rel="stylesheet" type="text/css" href="<?php echo get_template_directory_uri(); ?>/css/style2.css" />
<link rel="stylesheet" type="text/css" href="<?php echo get_template_directory_uri(); ?>/css/style3.css" />
<link rel="stylesheet" type="text/css" href="<?php echo get_template_directory_uri(); ?>/css/style4.css" />
Run Code Online (Sandbox Code Playgroud)

喜欢编码.


Ben*_*cot 6

您的源代码不包含文件名... bloginfo('stylesheet_url') 仅返回指向您的样式表...文件夹 URL 的链接,通常是主题文件夹。您还需要附加文件夹(如果有)和 filename.css

请记住始终牢记 WordPress 标准进行编码。链接到样式表不是最佳实践。这可以实现适当的缓存和效率,并且从长远来看更容易。

从我上周末读到的 300 页免费书 - WordPress AJAX,第 53 页:

// load styles + conditionally load an IE 7 stylesheet
add_action('init', 'my_theme_register_styles');
function my_theme_register_styles() { 
//Register styles for later use 
    wp_register_style('my_theme_style1', get_stylesheet_directory_uri() . '/style1.css', array(), '1.0', 'all'); 
    wp_register_style('my_theme_style2', get_stylesheet_directory_uri() . '/style2.css', array('my_theme_style1'), '1.0', 'all'); 
    wp_register_style('my_theme_style3', get_stylesheet_directory_uri() . '/style3.css', array('my_theme_style1', 'my_theme_style2'), '1.0', 'all'); 
    global $wp_styles; 
    $wp_styles->add_data( 'my_theme_style3', 'conditional', 'lte IE 7' );
}
Run Code Online (Sandbox Code Playgroud)

将其放入您的functions.php 或header.php 中。它正确地有条件地加载 IE 的样式表...