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

时间:2017-04-08 21:32:06

标签: php wordpress wordpress-theming

编码时我突然遇到错误 - wordpress - >主题: enter image description here

我不明白为什么会这样,因为我有一个index.php页面。还有css样式表。 style.css还有以下注释

的style.css

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

这是文件夹结构

enter image description here

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

3 个答案:

答案 0 :(得分:9)

<强>解 解决方法实际上非常简单。我发现很难找到一个好的资源来解答,所以我在这里回答。

缺少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
*/

答案 1 :(得分:4)

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

root中的主题css文件 - &gt;然后排队第二个样式表,其中包含所有样式 - 如果你想要它在/ 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/

答案 2 :(得分:0)

我也发生了同样的事情。我已经拥有所有必需的文件(因为两个文件仅需要索引和样式),我注意到,如果您有一个用于style.css文件的文件夹,则会收到上述错误消息。

因此,我进行了交叉检查,甚至移动了,并从主文件夹中删除了索引文件。

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

我不知道为什么会这样。但似乎我需要在style文件夹或style.css文件内放置一个索引文件,以将其放置在主文件夹中。