Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/41.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不读取样式表_Php_Css_Wordpress_Wordpress Theming - Fatal编程技术网

Php Wordpress不读取样式表

Php Wordpress不读取样式表,php,css,wordpress,wordpress-theming,Php,Css,Wordpress,Wordpress Theming,我是wordpress开发的新手。我正在学习发展一个新的主题。我知道对于basic来说,wordpress主题只有两个绝对必要的文件。为了进行测试,我创建了index.php文件和style.css文件,并尝试将其用作主题。但我在做这件事时面临着一些问题 正在读取index.php文件,内容显示在主页上,但css没有从style.css文件加载。第一条注释被读取,因为主题信息可以在主题细节部分看到,但是css没有被加载 我有两种错误,第一种 “加载资源失败:服务器响应状态为404(未找到)” 请

我是wordpress开发的新手。我正在学习发展一个新的主题。我知道对于basic来说,wordpress主题只有两个绝对必要的文件。为了进行测试,我创建了index.php文件和style.css文件,并尝试将其用作主题。但我在做这件事时面临着一些问题

正在读取index.php文件,内容显示在主页上,但css没有从style.css文件加载。第一条注释被读取,因为主题信息可以在主题细节部分看到,但是css没有被加载

我有两种错误,第一种

“加载资源失败:服务器响应状态为404(未找到)” 请参阅图片:

以及, “GET net::ERR_中止404(未找到)”

起初,我试图包含样式表thorugh
标记,但在出现错误后,我尝试了另一种方法将脚本排队-通过funstions.php文件,但后来我什么也没看到,没有错误,也没有样式

似乎什么都不管用,我尝试了很多次

index.php:-

<!doctype HTML>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Gym</title>
        <link rel="stylesheet" href="style.css">
    </head>
    <body>
        <div>
            Testing theme development
        </div>
        <div class="top-ribbon top-ribbon-left"></div>
        <div class="top-ribbon top-ribbon-right"></div>
    </body>
</html>
functions.php

<?php

function includeResources(){
    wp_enqueue_style('style', get_stylesheet_uri());
}

add_action('wp_enqueue_scripts', 'includeResources');

?>

这就是它的实际外观:

您的样式表不在WordPress安装的根目录(
/style.css
)中,而是在主题目录中。这就是为什么您不应该使用HTML
链接
属性,而应该使用
wp\u enqueue\u脚本
操作中的函数。你可以用这个官员

此外,您的
functions.php
无效,因为
style.css
未声明为字符串。应该抛出一个PHP错误。 更改此
wp\u enqueue\u样式('style',style.css,false)
to
wp_enqueue_style('style',get_stylesheet_uri())
此外,由于输入错误,您想要包含的函数不存在。将函数重命名为
includeResources
,而不是
incolderesources
(切换u和l)。

问题在于将样式路径错误地添加到标题中。 示例:bluebezer.com.br/style.css

您应该指向css所在的文件夹,该文件夹位于主题内,而不是站点的根目录。 示例:bluebezer.com/wp-content/themes/your-name/style.css

要获取主题的路径,请使用函数get_template_directory_uri()

需要注意的是,此函数将通过wp_head()自动调用站点标题的样式;功能;它应该出现在所有wordpress主题标题中

wp_头();该函数负责自动显示来自插件、操作和wordpress面板设置的标题、脚本、样式、目标和其他信息。然后它必须出现在所有wordpress标题中,否则在开发过程中会出现各种错误和困难

另一个重要的功能是:wp_footer(); 它负责调用额外的信息,如脚本和其他类似于wp_head()的设置;她必须始终出现在示例的页脚中:

    <!-- ... other codes ...-->
    <?php wp_footer(); ?>

</body>
</html>

这里有一个输入错误:“function inculdeResources()”您好!事实上,首先我尝试在includeResources函数参数中使用“get_stylesheet_uri()”函数,但即便如此,它也没有成功;不工作,然后我在wordpress抄本上读了一些东西,我试图使用它,但它没有;我帮不上忙。我已经更新了问题中的代码,这也不起作用,即使在wp_页脚之后,它也不能按需要工作。
<html <?php language_attributes(); ?>>
    <head>
        <!-- ... other codes ...-->

        <link rel="stylesheet" type="text/css" href="<?php echo get_template_directory_uri() . '/style.css'; ?>" />

        <!-- This wp_head function must be present in all wordpress headers. -->
        <?php wp_head(); ?>
    </head>
add_action( 'wp_enqueue_scripts', 'wpsites_new_style_sheet' );
function wpsites_new_style_sheet() {
    //registering a new style in wordpress
    wp_register_style( 'new-style', get_template_directory_uri() .'css/new-style.css', array(), '1.0');
    //stating that the new style should be displayed in wordpress
    wp_enqueue_style( 'new-style' );    
}
    <!-- ... other codes ...-->
    <?php wp_footer(); ?>

</body>
</html>