简体   繁体   English

CSS未链接到HTML页面模板

[英]CSS not linking to HTML Page Template

I tried in the localhost wordpress and it works fine there. 我在localhost wordpress尝试过,在那工作正常。

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. 但是,当我尝试使用实时网站并尝试将CS​​S文件链接到HTML文件时,却没有CSS效果。

I link the CSS to my HTML file using the following address location : 我使用以下地址将CSS链接到HTML文件:

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

How can I possibly link the CSS files to my HTML? 如何将CSS文件链接到HTML?

PS : I am linking my HTML file to my PHP file to create the Page Template as PS:我将HTML文件链接到PHP文件以创建页面模板,如下所示:

require(TEMPLATEPATH.'/file1.html')

Also there is no folder named wordpress in the control panel directory. 此外,控制面板目录中没有名为wordpress文件夹。 The address location for my HTML and CSS file is /home3/username/public_html/wp-content/themes/ThemeName/file1.html 我的HTML和CSS文件的地址位置是/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. Wordpress为此提供了一些功能,例如get_stylesheet_directory_uri ,它返回当前主题文件夹的uri。 So to link your css you should do this: 因此,要链接您的CSS,您应该执行以下操作:

<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: 但是您应该考虑将您的CSS与来自functions.php链接,因为这是一种更好的做法:

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. 这样,当wp_head()时,WordPress将在wp_head()为样式表添加<link>标记。

可以将CSS文件包含在主题中,例如<link rel="stylesheet" type="text/css" href="<?php bloginfo('template_url') ?>/file1.css"/>或使用wp_enque_style ()功能

If you store css and html in same folder. 如果您将css和html存储在同一文件夹中。 I think It works: 我认为它有效:

  <link href="file1.css" rel="stylesheet" />

我认为您需要指定类型:

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

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

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