我一直在努力将 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>
这是我在萤火虫中发现的问题:
http://prntscr.com/4l5dox
但我不确定这是否都是问题:)
那么,请问你对我有什么建议?
谢谢。
尝试使用enqueue_style
http://codex.wordpress.org/Function_Reference/wp_enqueue_style
在主题中创建自己的页面,并在函数.php文件中包含页面。
你试过这个吗?
<link rel="stylesheet" href="<?php echo get_stylesheet_directory(); ?>css/style.css" />
此外,最好看看上述函数的输出是什么,看看您是否需要在 css 之前添加斜杠。
或者您可以只添加文件路径。在wordpress之外,我认为这些功能不起作用。
<link rel="stylesheet" href="./css/style.css" />
试试这个
<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" />
尝试从导入 url 中删除第一个斜杠。
@import url('css/skel.css');
@import url('css/style.css');
@import url('css/style-desktop.css');
@import url('css/style-noscript.css');
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
注意:无论您需要什么样式.css在您的基本主题文件夹中,因为 wordpress 只解析该文件的主题元
theme1/style.css
theme1/header.php
theme1/css/other.css
在标题中.php
<link rel="stylesheet" href="<?php bloginfo( 'stylesheet_url' ); ?>" type="text/css"/>
在样式中.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
这应该非常简单,无论您使用什么主题文件夹,都可以将其添加到您的函数.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文件位于主样式附近.css文件你应该很好