【问题标题】:WordPress Theme: Standalone theme need index.php file ERRORWordPress 主题:独立主题需要 index.php 文件错误
【发布时间】:2017-09-04 03:56:16
【问题描述】:

编码时突然出错 - wordpress -> 主题:

我不明白为什么会这样,因为我有一个 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

这是文件夹结构

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

【问题讨论】:

  • 你缺少一个 template.php 和 style.css
  • 但是我的css文件夹中有style.css。我一直没有 template.php 并且主题正在工作,即没有损坏和活跃。为什么现在会坏
  • 是不是因为我在wordpress admin里新建了一个页面?
  • 你必须在主题文件夹中有style.css或者从functions.php链接它,否则它不起作用,试试吧
  • 我的入队函数是functions.php,即wp_enqueue_style('custom-style', get_template_directory_uri().'/css/style.css');

标签: php wordpress wordpress-theming


【解决方案1】:

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

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

【讨论】:

  • @Rathinam 抱歉回复晚了。将此代码复制并粘贴到您的 css 文件中
  • 这仅适用于您的意图是制作一个 25 岁的儿童主题。如果您的主题是独立的,Spencer 有答案。
  • 解决了我的问题。
【解决方案2】:

为了让 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/

【讨论】:

  • @Rathinam - 转到我在上面的答案中发布的链接,并将其与您所写的内容进行比较。或者直接从 wordpress 复制/粘贴,然后编辑内容。
【解决方案3】:

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

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

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

我不知道为什么会这样。但似乎我需要将样式文件夹中的索引文件或 style.css 文件放置在主文件夹中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-16
    • 1970-01-01
    • 1970-01-01
    • 2013-02-03
    • 2015-03-05
    相关资源
    最近更新 更多