Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php WordPress-CSS导入对我不起作用_Php_Css_Wordpress_Themes - Fatal编程技术网

Php WordPress-CSS导入对我不起作用

Php WordPress-CSS导入对我不起作用,php,css,wordpress,themes,Php,Css,Wordpress,Themes,我是WordPressN00B。我似乎无法将简单的CSS导入我的页面 这是我曾经尝试过的: index.php <link href="style.css" rel="stylesheet" type="text/css"> 我也试过: index.php: <link href="<?php bloginfo('stylesheet_url'); ?>" rel="stylesheet" type="text/css"> <link href="s

我是WordPressN00B。我似乎无法将简单的CSS导入我的页面

这是我曾经尝试过的:

index.php

<link href="style.css" rel="stylesheet" type="text/css">
我也试过:

index.php:

<link href="<?php bloginfo('stylesheet_url'); ?>" rel="stylesheet" type="text/css">
<link href="style.css" rel="stylesheet" type="text/css">
<link href="http://fonts.googleapis.com/css?family=Varela" rel="stylesheet" type="text/css">
<link href="css/bootstrap.css" rel="stylesheet">
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css">
<link href="css/custom-styles.css" rel="stylesheet" type="text/css">

导入语句后不应使用冒号:

@import url("css/bootstrap.css");

这就是说,您正在做的事情通常被渲染为不良实践。如果CSS文件可以帮助导入其他CSS,则不应导入其他CSS,因为它需要您同步下载文件:

我下载styles.css

---->然后下载bootstrap.css,因为它已导入

最好是直接在HTML文档中导入这两者:

<link rel="stylesheet" href="styles.css"/>
<link rel="stylesheet" href="bootstrap.css"/>


有关详细信息。

导入语句后不应使用冒号:

@import url("css/bootstrap.css");

这就是说,您正在做的事情通常被渲染为不良实践。如果CSS文件可以帮助导入其他CSS,则不应导入其他CSS,因为它需要您同步下载文件:

我下载styles.css

---->然后下载bootstrap.css,因为它已导入

最好是直接在HTML文档中导入这两者:

<link rel="stylesheet" href="styles.css"/>
<link rel="stylesheet" href="bootstrap.css"/>


获取更多信息。

您对wordpress的做法是错误的。你应该赋予你的样式表。下面应该放在functions.php文件中

function enqueue_styles() {
    wp_enqueue_style( 'stylesheet', get_template_directory_uri() . '/style.css');
}
如果您使用的是示例中的硬编码链接,那么这些链接应该添加到header.php中,但是这是一种不好的做法,因为Wordpress有自己的方法来处理依赖关系和冲突

查看

另外,如前所述,使用@import加载多个样式表通常是不好的做法。您可以使用enqueue加载所有这些脚本,只需确保您需要的脚本最后加载:

    function enqueue_styles() {
 wp_enqueue_style( 'stylesheet', 'netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css');
 wp_enqueue_style( 'stylesheet', 'http://fonts.googleapis.com/css?family=Varela');
 wp_enqueue_style( 'bootstrap-css', get_template_directory_uri() . '/css/bootstrap.min.css', array() );
 wp_enqueue_style( 'stylesheet', get_template_directory_uri() . '/style.css');
 wp_enqueue_style( 'stylesheet', get_template_directory_uri() . '/css/custom-styles.css');
    }
然后像这样钩住它:

add_action( 'wp_enqueue_scripts', 'enqueue_styles' );

你这样做对wordpress来说是错误的。你应该赋予你的样式表。下面应该放在functions.php文件中

function enqueue_styles() {
    wp_enqueue_style( 'stylesheet', get_template_directory_uri() . '/style.css');
}
如果您使用的是示例中的硬编码链接,那么这些链接应该添加到header.php中,但是这是一种不好的做法,因为Wordpress有自己的方法来处理依赖关系和冲突

查看

另外,如前所述,使用@import加载多个样式表通常是不好的做法。您可以使用enqueue加载所有这些脚本,只需确保您需要的脚本最后加载:

    function enqueue_styles() {
 wp_enqueue_style( 'stylesheet', 'netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css');
 wp_enqueue_style( 'stylesheet', 'http://fonts.googleapis.com/css?family=Varela');
 wp_enqueue_style( 'bootstrap-css', get_template_directory_uri() . '/css/bootstrap.min.css', array() );
 wp_enqueue_style( 'stylesheet', get_template_directory_uri() . '/style.css');
 wp_enqueue_style( 'stylesheet', get_template_directory_uri() . '/css/custom-styles.css');
    }
然后像这样钩住它:

add_action( 'wp_enqueue_scripts', 'enqueue_styles' );


谢谢我很久没用进口货了。不过,我还是有问题。我更愿意将它们导入HTML,不过,我读到WordPress更常见?正如我前面所说,将所有样式表直接导入HTML是很常见的,因为它允许您异步下载它们。它不仅在wordpress中很常见,在所有网站中也很常见。@dustIndowell 22如果它仍然不起作用,那么它必须是文件路径。值得注意的是,路径是相对于样式表的源的,而不是相对于文档的。@JoshCrozier我在尝试将CSS直接导入index.php页面时编辑了我的主要帖子。这是我第一次尝试,我只是认为这是WordPress主题的错误方式。我100%确信路径名是正确的。@dustinowell 22您能提供一个链接到您试图导入CSS的网站吗?谢谢。我很久没用进口货了。不过,我还是有问题。我更愿意将它们导入HTML,不过,我读到WordPress更常见?正如我前面所说,将所有样式表直接导入HTML是很常见的,因为它允许您异步下载它们。它不仅在wordpress中很常见,在所有网站中也很常见。@dustIndowell 22如果它仍然不起作用,那么它必须是文件路径。值得注意的是,路径是相对于样式表的源的,而不是相对于文档的。@JoshCrozier我在尝试将CSS直接导入index.php页面时编辑了我的主要帖子。这是我第一次尝试,我只是认为这是WordPress主题的错误方式。我100%确信路径名是正确的。@dustinowell 22您能提供一个链接到您试图导入CSS的网站吗?我回滚了您的修订版,因为您从问题中删除了问题代码。为了让下面的答案有意义,冒号在你的问题中是必要的。你确定那些文件路径是正确的吗?@David,我很确定。我在工作静态html站点上所做的唯一更改是将链接添加到style.css,并将文件扩展名从.html更改为.phpI,因为您从问题中删除了问题代码,所以我回滚了您的修订。为了让下面的答案有意义,冒号在你的问题中是必要的。你确定那些文件路径是正确的吗?@David,我很确定。我对静态html站点所做的唯一更改是将链接添加到style.css,并将文件扩展名从.html更改为.phpOkay。所以我会复制函数中的最后一行来添加多个样式?那么服务器上没有的样式呢?@dustIndowell 22已编辑以显示如何加载所有内容。谢谢。现在我只需要弄清楚如何包含functions.php。您不需要包含它。这是一个默认的wordpress文件,应该位于主题的顶部目录中。如果没有,只需创建一个名为functions.php的文件,wordpress就会自动加载它。@PieterGoosen谢谢,修复了。好的。所以我会复制函数中的最后一行来添加多个样式?那么服务器上没有的样式呢?@dustIndowell 22已编辑以显示如何加载所有内容。谢谢。现在我只需要弄清楚如何包含functions.php。您不需要包含它。这是一个默认的wordpress文件,应该位于主题的顶部目录中。如果没有,只需创建一个名为functions.php的文件,wordpress就会自动运行