CSS没有链接到HTML页面模板 [英] CSS not linking to HTML Page Template

查看:125
本文介绍了CSS没有链接到HTML页面模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 localhost wordpress 中试过,它在那里正常工作。网站,并尝试将CS​​S文件链接到HTML文件我没有得到CSS效果。



我使用以下地址位置将CSS链接到我的HTML文件:

 < link href =/ wordpress / wp-content / themes / ThemeName / file1.css =stylesheet/ > 

如何将CSS文件链接到我的HTML?



PS:我将我的HTML文件链接到我的PHP文件以创建页面模板为

  require TEMPLATEPATH。'/ file1.html')

也没有文件夹名称为 wordpress 在控制面板目录中。
我的HTML和CSS文件的地址位置是 /home3/username/public_html/wp-content/themes/ThemeName/file1.html

解决方案

您不应在模板中编写完整路径。 Wordpress为此提供了函数,如 get_stylesheet_directory_uri ,它返回当前主题文件夹的uri。所以要链接你的CSS你应该这样做:

 < link href =<?php echo get_stylesheet_directory_uri();? > /file1.cssmedia =allrel =stylesheettype =text / css/> 

但是您应该考虑将您的css从 functions.php
$ p $ function my_scripts()
{
wp_enqueue_style('my_style ',get_stylesheet_directory_uri()。'/file1.css');
}
add_action('wp_enqueue_scripts','my_scripts');

这样Wordpress会添加< link> wp_head()时,头部中的样式表的c>标签。


I tried in the localhost wordpress and it works fine there.

But when I try for my live website and try to link the CSS files to the HTML file I do not get the CSS effects.

I link the CSS to my HTML file using the following address location :

<link href="/wordpress/wp-content/themes/ThemeName/file1.css" rel="stylesheet" />

How can I possibly link the CSS files to my HTML?

PS : I am linking my HTML file to my PHP file to create the Page Template as

require(TEMPLATEPATH.'/file1.html')

Also there is no folder named wordpress in the control panel directory. The address location for my HTML and CSS file is /home3/username/public_html/wp-content/themes/ThemeName/file1.html

解决方案

You shouldn't write full path like that in your template. Wordpress provide functions for that, like get_stylesheet_directory_uri that returns the uri of your current theme folder. So to link your css you should do this:

<link href="<?php echo get_stylesheet_directory_uri(); ?>/file1.css" media="all" rel="stylesheet" type="text/css" />

But you should consider linking your css from functions.php as it's a better practice:

function my_scripts()
{
  wp_enqueue_style( 'my_style', get_stylesheet_directory_uri() . '/file1.css' );
}
add_action( 'wp_enqueue_scripts', 'my_scripts' );

That way Wordpress will add the <link> tag for your stylesheet in the head when wp_head() is called.

这篇关于CSS没有链接到HTML页面模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆