WordPress 主题:独立主题需要index.php 文件错误

问题描述 投票:0回答:5

我在编码时突然遇到错误 - wordpress -> theme:

我不明白为什么会出现这种情况,因为我有一个index.php页面。 CSS 样式表也在那里。 style.css 也有以下注释

样式.css

Theme Name: samirTheme
Author: samir
Author URI: www.wordpress.com
Version: 1.0
Description: This is a cool theme
Template: Test1

这是文件夹结构

WordPress 新手。很困惑为什么主题被破坏并且没有出现在 WordPress 中。有什么想法吗?

php wordpress wordpress-theming
5个回答
36
投票

解决方案 解决的办法其实很简单。我发现很难找到一个好的答案资源,所以我在这里回答。

注释标题中缺少 style.css:模板:主题,即

/*
 Theme Name:   samirTheme
 Theme URI:    http://example.com/twenty-fifteen-child/
 Description:  Twenty Fifteen Child Theme
 Author:       John Doe
 Author URI:   http://example.com
 Template:     twentyfifteen <--------------------------------------------
 Version:      1.0.0
 License:      GNU General Public License v2 or later
 License URI:  http://www.gnu.org/licenses/gpl-2.0.html
 Tags:         light, dark, two-columns, right-sidebar, responsive-layout, accessibility-ready
 Text Domain:  twenty-fifteen-child
*/

10
投票

为了让 WordPress 将主题模板文件集识别为有效主题,style.css 文件需要位于主题的根目录中,而不是子目录中。

所以根目录中的主主题 css 文件 -> 然后将包含所有样式的第二个样式表加入队列 - 如果你希望它位于 /css/

css 标题示例:

/*
Theme Name: Twenty Seventeen
Theme URI: https://wordpress.org/themes/twentyseventeen/
Author: the WordPress team
Author URI: https://wordpress.org/
Description: Twenty Seventeen brings your site to life with immersive featured images and subtle animations. With a focus on business sites, it features multiple sections on the front page as well as widgets, navigation and social menus, a logo, and more. Personalize its asymmetrical grid with a custom color scheme and showcase your multimedia content with post formats. Our default theme for 2017 works great in many languages, for any abilities, and on any device.
Version: 1.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Text Domain: twentyseventeen
Tags: one-column, two-columns, right-sidebar, flexible-header, accessibility-ready, custom-colors, custom-header, custom-menu, custom-logo, editor-style, featured-images, footer-widgets, post-formats, rtl-language-support, sticky-post, theme-options, threaded-comments, translation-ready
This theme, like WordPress, is licensed under the GPL.
Use it to make something cool, have fun, and share what you've learned with others.
*/

欲了解更多信息,请阅读以下内容: https://developer.wordpress.org/themes/basics/main-stylesheet-style-css/


1
投票

同样的事情也发生在我身上。我拥有所有必要的文件(因为两个文件只需要索引和样式),我注意到一件事,如果您有 style.css 文件的文件夹,您将收到如上所述的错误消息。

所以我交叉检查,甚至移动并删除了主文件夹中的索引文件。

如果我从主文件夹中删除index.php文件,并将其放在css文件夹中,它就可以工作。

我不知道为什么会这样。但我觉得它需要 style 文件夹内的索引文件或 style.css 文件放置在主文件夹中。


0
投票

此错误也可能是由字符编码引起的。例如:

$ file -I style.css
style.css: text/plain; charset=us-ascii
$ file -I style-error.css
style-error.css: text/plain; charset=utf-16le

将网页中的 CSS 代码(例如,教程文章)复制并粘贴到 CSS 文件本身中是出现此问题的常见原因。如果 CSS 代码包含特殊字符,有时文件编辑器会尝试更改 CSS 文件的字符编码以适应所有添加的字符。

在提出这个问题很久之后,但希望能帮助其他人寻找答案。


0
投票

重命名自定义主题后,我遇到了同样的问题。所以发生的事情是 Wp 保留了空的旧主题文件夹。所以我所要做的就是删除那个旧文件夹,一切就都好了。我希望这对你也有帮助。 祝你好运!

© www.soinside.com 2019 - 2024. All rights reserved.