我正致力于将Html主题转换为WordPress,此主题包含多个.CSS
文件。
我尝试了几种方法将它们调用head.php
,但都不成功!
我尝试的方式:
进入style.css
:
@import url('/css/skel.css');
@import url('/css/style.css');
@import url('/css/style-desktop.css');
@import url('/css/style-noscript.css');
并将其转换为Header.php
:
<link href="<?php bloginfo('stylesheet_url'); ?>" rel="stylesheet" type="text/css" />
我在Header.php
尝试的其他方式:
<link rel="stylesheet" href="<?php get_stylesheet_directory(); ?>css/skel.css" />
<link rel="stylesheet" href="<?php get_stylesheet_directory(); ?>css/style.css" />
<link rel="stylesheet" href="<?php get_stylesheet_directory(); ?>css/style-desktop.css" />
<link rel="stylesheet" href="<?php get_stylesheet_directory(); ?>css/style-noscript.css" />
也用于:
stylesheet_url
template_directory
其他信息:
Header.php
代码
<!DOCTYPE HTML>
<html>
<head>
<title><?php bloginfo( 'title' ); ?></title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<!--[if lte IE 8]><script src="<?php echo get_template_directory_uri(); ?>/css/ie/html5shiv.js"></script><![endif]-->
<script src="<?php echo get_template_directory_uri(); ?>/js/jquery.min.js"></script>
<script src="<?php echo get_template_directory_uri(); ?>/js/skel.min.js"></script>
<script src="<?php echo get_template_directory_uri(); ?>/js/init.js"></script>
<noscript>
<link rel="stylesheet" href="<?php bloginfo( 'stylesheet_url' ); ?>" type="text/css"/>
</noscript>
<!--[if lte IE 8]><link rel="stylesheet" href="<?php bloginfo( 'stylesheet_url' ); ?>/css/ie/v8.css" /><![endif]-->
<?php wp_head(); ?>
</head>
<body>
这是我用firebug找到的问题:
但我不确定这是否都是问题:)
那么,请问你有什么建议吗?
谢谢。
答案 0 :(得分:2)
尝试使用enqueue_style
http://codex.wordpress.org/Function_Reference/wp_enqueue_style
在主题中创建您自己的页面,并在functions.php文件中包含页面。
答案 1 :(得分:0)
你试过这个吗?
<link rel="stylesheet" href="<?php echo get_stylesheet_directory(); ?>css/style.css" />
同样很高兴看到上述函数的输出是什么,看看你是否需要在css之前添加斜杠。
或者你可以添加文件路径。在wordpress之外,我不认为这些功能有效。
<link rel="stylesheet" href="./css/style.css" />
答案 2 :(得分:0)
get_stylesheet_directory
返回绝对服务器路径,而不是URI。您需要回复get_stylesheet_directory_uri()
。请注意,这不会返回斜杠。您需要通过添加来修改源代码。例如:
<link rel="stylesheet" href="<?php echo get_stylesheet_directory_uri(); ?>/css/skel.css" />
请参阅相关的WordPress文档:http://codex.wordpress.org/Function_Reference/get_stylesheet_directory_uri
答案 3 :(得分:0)
试试这个
<link href="<?php echo home_url('/');?>wp-content/themes/tmeme name/css/css name.css" rel="stylesheet" type="text/css"/>
或
<link rel="stylesheet" href="<?php echo get_stylesheet_directory_uri(); ?>/css/css name.css" />
答案 4 :(得分:0)
尝试从导入网址中删除第一个斜杠。
@import url('css/skel.css');
@import url('css/style.css');
@import url('css/style-desktop.css');
@import url('css/style-noscript.css');
答案 5 :(得分:0)
注意:无论您需要什么样的基本主题文件夹上的style.css,因为wordpress只解析该主题元素的文件
theme1/style.css
theme1/header.php
theme1/css/other.css
在header.php中
<link rel="stylesheet" href="<?php bloginfo( 'stylesheet_url' ); ?>" type="text/css"/>
在style.css中(需要包含主题信息)
/*
Theme Name: Theme1
Theme URI:
Description: Sample Theme
Author:
Author URI:
License: GNU General Public License v2.0
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Version: 1.0
*/
@import url("css/other.css"); //sample css file
答案 6 :(得分:0)
这应该非常简单,无论你使用什么主题文件夹,都要将它添加到你的functions.php文件
function add_stylesheets(){ ?>
<link rel="stylesheet" href="<?php echo get_stylesheet_directory_uri().'/css-filepath-inside-theme-folder-here/somefile.css ?>">
//Add the function to the wordpress head
add_action('wp_head','add_stylesheets');
只要css文件位于主要的style.css文件附近,你应该是好的