【问题标题】:Template Dropdown not showing up within Wordpress administrator page模板下拉菜单未显示在 Wordpress 管理员页面中
【发布时间】:2010-10-21 13:10:43
【问题描述】:

我正在开发一个基于 Wordpress 的项目,我刚刚通过上传模板文件向安装中添加了一个新模板。我正在创建一个将使用我的新模板的新页面,突然,“页面属性”框中的“模板”下拉菜单消失了。

我正在使用 Wordpress 3.0.1。

更新: 我看到一个网站告诉我恢复到默认模板,然后恢复到我的自定义模板。显然它有效,但我仍然对触发这个错误的原因感到困惑。此外,任何有关此错误的其他知识或指示都会有很大帮助,因为我的工作需要我修补此问题(并可能将错误修复提交给 Wordpress)。谢谢!

【问题讨论】:

    标签: wordpress wordpress-theming


    【解决方案1】:

    如果您从模板目录中禁用或删除了 style.css,那么它也将不起作用。

    所以模板目录必须有style.css,然后模板目录就会显示出来。当您尝试从模板目录中删除 style.css 或使用 css 文件夹中的 style.css 时,您必须在模板目录中放置一个 style.css。

    谢谢

    【讨论】:

    • 我遇到了同样的问题。我已经删除了工具栏,并且也禁用了模板下拉菜单。这很有帮助
    • 这解决了我的问题,因为它被提及的频率比其他建议少得多
    • 在我的情况下,不是 style.css 不存在,而是版本号与模板上的版本号不匹配。
    【解决方案2】:

    Morichika 是正确的。我遇到了同样的问题,但后来它自己解决了:

    <?php
        /**
        * Template Name: Front Page
        */
    ?>
    

    【讨论】:

      【解决方案3】:

      我为此找到了不同的解决方案。我重新激活了我的自定义主题,但问题仍然存在。然后在自定义页面模板代码的最顶部部分,它实际上定义了模板的名称,如下所示:

      <?php
          /*
           Template Name: Front Page
          */
      ?>
      

      我这样做了:

      <?php
          /**
          * Template Name: Front Page
          */
      ?>  
      

      然后刷新了管理面板,它出现了。看起来有点奇怪,但它对我有用。很高兴分享这个。

      【讨论】:

      • 在我的情况下,反之亦然。
      【解决方案4】:

      将 style.css 放在您的主题目录中,而不是 css 文件夹中。或者

      <?php
          /*
           Template Name: Front Page
          */
      ?>
      

      “模板名称:”之间不能有空格。

      【讨论】:

      • 你是对的,解决了它。冒号左边没有空格。
      【解决方案5】:

      我尝试了许多建议的答案。在我的情况下没有任何工作。

      模板下拉菜单未显示的可能原因是您的主题文件夹中缺少index.php。

      只需创建一个空的,以防您的层次结构不需要一个。但是该文件的存在使选项能够选择页面模板并抑制选择主题页面中的错误消息顺便说一句

      【讨论】:

      • 正是这里发生的事情(Gutenberg FYI),但我仍然清理了很多文件夹。添加一个 empy index.php 就可以了!
      【解决方案6】:

      我通过确保主题根中的style.css 包含主题cmets 设法解决了这个问题。我删除了整个样式表并删除了模板下拉菜单。

      把它放在你的主题根style.css的顶部。

      /wp-content/themes/YOUR_THEME/style.css

      /*
      Theme Name: Twenty Thirteen
      Theme URI: http://wordpress.org/themes/twentythirteen
      Author: the WordPress team
      Author URI: http://wordpress.org/
      Description: The 2013 theme for WordPress takes us back to the blog, featuring a full range of post formats, each displayed beautifully in their own unique way. Design details abound, starting with a vibrant color scheme and matching header images, beautiful typography and icons, and a flexible layout that looks great on any device, big or small.
      Version: 1.0
      License: GNU General Public License v2 or later
      License URI: http://www.gnu.org/licenses/gpl-2.0.html
      Tags: black, brown, orange, tan, white, yellow, light, one-column, two-columns, right-sidebar, flexible-width, custom-header, custom-menu, editor-style, featured-images, microformats, post-formats, rtl-language-support, sticky-post, translation-ready
      Text Domain: twentythirteen
      
      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://codex.wordpress.org/Theme_Development#Theme_Stylesheet

      或者,如果您有自定义主题...

      /*
      Theme Name: My Wordpress Theme
      Theme URI: https://example.tk
      Author: Me
      Author URI: https://example.tk
      Description: This is my custom theme
      Version: 1.0
      */
      

      【讨论】:

      • 我遇到了同样的问题,使用 sass 编译我的 css,它正在删除 cmets。由于某种原因,唯一相关的问题是页面模板停止工作 - 很奇怪。
      【解决方案7】:

      我知道这个问题太迟了,但我修复它添加

      Version: 0.1 alpha

      在themeFolder/style.css的cmets中

      这是我的style.css 完成我的主题

      /*
        Theme Name: Stockout Theme
        Theme URI: http://stockout.com.uy/myTheme
        Author: MauriPastorini
        Author URI: http://stockout.com.uy
        Description: This is a theme for stockout page
        Version: 0.1 alpha
      */
      

      我希望有人觉得这很有用

      【讨论】:

      • 确实非常有用!只需更新我的 style.css 中的版本就可以了。非常感谢!
      【解决方案8】:

      我在使用 WordPress 3.2.1 时遇到了完全相同的问题。我添加了一个新模板,菜单从页面添加/编辑屏幕中消失了。解决方案是切换回默认的 211 主题结束,然后立即切换回我的自定义主题。模板下拉菜单再次开始出现。

      顺便说一句,您说“恢复到默认模板,然后恢复到我的自定义模板”,但我很确定您的意思是 主题。我猜你是在哪里看到的:

      http://wordpress.org/support/topic/template-file-drop-down-not-appearing

      看起来这个错误至少已经存在了几年。我提交了一份报告: http://core.trac.wordpress.org/ticket/18324

      【讨论】:

        【解决方案9】:

        不久前我遇到了这个问题,经过大量搜索后找到了一个问题解决方案——有时在安装中切换到另一个主题,然后切换回主主题会使你的模板出现。我知道这听起来很奇怪,但为我工作了一段时间。

        【讨论】:

          【解决方案10】:

          试试这个。模板将可用于页面和帖子

          <?php
          /**
           * Template Name: Blog Post
           * Template Post Type: post, page
          ?>
          

          【讨论】:

            【解决方案11】:

            我已经有这个问题两天了。这个论坛和一些测试后来完成了工作。这是我所缺少的。


            确保您的主题文件夹中有 style.css。

            style.css 必须在文件顶部有一个有效的注释部分。 这至少意味着:

            /*!
            Template: your-theme
            */
            

            如果您使用的是 SASS 或 LESS,请确保您有一个“!”就在宣布您的评论之后。这是为了防止 SASS 或 LESS 删除您的评论部分。

            确保一切顺利。您可以前往“外观 > 主题”。主题列出后,如果没有,那么一切都应该没问题。否则,它会被写成“Broken Themes”,你仍然有一些问题需要解决。

            【讨论】:

              【解决方案12】:

              sass 删除了我孩子 style.css 中的内容。一旦我添加回 cmets,模板下拉菜单就会再次显示。 /* 主题名称:Sometheme Child 描述:Sometheme 的子主题。 模板:主题 版本:1.1 文本域:sometheme-child */

              【讨论】:

              • 为了避免 SASS 或 Gulp 删除 cmets 添加和感叹号,例如 /*! Comments */ 到您的评论标签
              【解决方案13】:

              如果您在主题根目录中添加了 0 个自定义模板文件,您将不会看到下拉列表。

              当至少有 1 个模板可用时,WordPress 生态系统会选择它并且下拉菜单将变得可见。

              将此添加到您的主题根目录中以进行尝试。

              <?php
              
              /*
               Template Name: Front Page
              */
              

              【讨论】:

                【解决方案14】:

                在 WordPress 5.8 中,他们已将可选择的自定义模板从“页面属性”部分下移出,因此无论您做什么,都不会在那里找到它(即使您像我一样花了 2 小时进行故障排除,哈哈)。

                自定义可选模板现已移至其自己的名为“模板”的框内。对我来说,它位于 WP 管理页面编辑器右侧边栏的顶部。如果您在屏幕选项设置中未选中它,则它可能不会显示,这些设置现在位于右上角的三个点下方 --> 首选项 --> 面板 --> 确保选中“模板”。

                我不确定我是否只是连续 2 小时忽略了它,或者它是否仅在我更改为不同的主题然后又改回来后才出现。

                【讨论】:

                  【解决方案15】:

                  我刚刚遇到了同样的问题,问题在于“模板名称”和冒号之间的间距。

                  /*
                    Template Name: template-name
                  */
                  

                  确保冒号前没有空格。

                  【讨论】:

                    【解决方案16】:

                    我找到了问题的根源。 它是主题根目录中的style.css 文件。

                    1. 必须是“UNIX 编码”。

                    2. 它必须包含所有带有“主题名称”、“版本”等的 cmets。

                    【讨论】:

                      【解决方案17】:

                      杰克尼科尔森是对的!您需要确保您的 style.css 包含完整的评论。示例如下:

                      以前我的是:

                      /*
                      Theme Name: Acadata
                      Theme URI: https://www.factorypattern.co.uk
                      Description: Custom
                      Author: Factory Pattern
                      Version: 1
                      License: GNU General Public License
                      License URI: license.txt
                      */
                      

                      然后我把它改成下面的,现在我可以看到我所有的模板了。

                      /*
                      Theme Name: Acadata
                      Theme URI: https://factorypattern.co.uk/
                      Description: Custom
                      Author: Factory Pattern
                      Author URI: https://factorypattern.co.uk/
                      Description: The Acadata theme for WordPress.
                      Version: 1.0
                      License: GNU General Public License v2 or later
                      License URI: http://www.gnu.org/licenses/gpl-2.0.html
                      Tags: black, brown, orange, tan, white, yellow, light, one-column, two-columns, right-sidebar, flexible-width, custom-header, custom-menu, editor-style, featured-images, microformats, post-formats, rtl-language-support, sticky-post, translation-ready
                      Text Domain: acadata
                      
                      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.
                      */
                      

                      【讨论】:

                        【解决方案18】:

                        如果您正在处理子主题,请特别设置您的 style.css 文件

                        /*
                        Theme Name: Theme Name
                        Theme URI: http: //mysite.com/
                        Description: This is a custom child theme for xxx theme
                        Author: My Name
                        Author URI: http: //mysite.com/
                        Template: template_name_in_lowercase
                        Version: 0.1
                        */

                        【讨论】:

                          【解决方案19】:

                          这对我有用,并在页面属性中显示模板选项。只需将 .php 文件放在主题根文件夹中。

                          <?php
                          /* template name: my custom template */
                          ?>
                          

                          【讨论】:

                            【解决方案20】:

                            关于这个问题有很多很好的答案,但一个明显的解决方案,最初让我忽略了,是在 仪表板 > 设置 > 阅读中仔细检查你想要设置“你的主页显示”到“静态页面”,然后取消选中“帖子页面”。

                            虽然主题和正确编码的主题文件在这种情况下发挥作用,但编辑页面屏幕上的页面属性区域未显示模板下拉菜单的原因可能是因为您选择了特定页面作为您的“帖子页面”,因此 WordPress 不会要求您使用自定义模板,因为它已经在使用 front-page.php 或 home.php (See WordPress Template Visual Hierarchy)。

                            希望这对像我这样拥有正确编码的模板文件但没有意识到已选择此设置的人有所帮助。

                            【讨论】:

                              【解决方案21】:

                              这对我来说也是一个问题,这是因为文件夹结构。主题手册告诉我应该像这样组织我的主题文件夹和文件:

                              assets (dir)
                                  - css (dir)
                                  - images (dir)
                                  - js (dir)
                              inc (dir)
                              template-parts (dir)
                                  - footer (dir)
                                  - header (dir)
                                  - navigation (dir)
                                  - page (dir)
                                  - post (dir)
                              404.php
                              archive.php
                              comments.php
                              footer.php
                              front-page.php
                              function.php
                              header.php
                              index.php
                              page.php
                              README.txt
                              rtl.css
                              screenshot.png
                              search.php
                              searchform.php
                              sidebar.php
                              single.php
                              style.php
                              

                              我尝试加载的页面模板位于/template-parts/page/template-contactus.php

                              我想这对 WordPress 来说太深了,所以我得到了这些目录,现在我的文件结构如下所示:

                              assets (dir)
                                  - css (dir)
                                  - images (dir)
                                  - js (dir)
                              inc (dir)
                              template-parts (dir)
                                  - section-content.php
                                  - template-contactus.php
                              404.php
                              archive.php
                              comments.php
                              footer.php
                              front-page.php
                              function.php
                              header.php
                              index.php
                              page.php
                              README.txt
                              rtl.css
                              screenshot.png
                              search.php
                              searchform.php
                              sidebar.php
                              single.php
                              style.php
                              

                              我现在可以看到模板下拉菜单并添加模板。

                              希望这对某人有所帮助。

                              【讨论】:

                                【解决方案22】:

                                在我的例子中,我调用了模板 schedule-template-v2.php,它不起作用,文件名需要是 schedulev2-template.php。一个简单的错误。

                                【讨论】:

                                • 创建页面模板时文件命名是否重要? @archie
                                • 是的,当然是道尔顿。
                                • 我的问题是,模板在文件夹树中更深,所以我把它们放在主题的根目录 /page-templates/
                                【解决方案23】:

                                除了以上所有内容之外,请确保您在右上角的屏幕选项面板中选中了“页面属性”,否则无论如何页面属性部分都不会显示。

                                【讨论】:

                                  【解决方案24】:

                                  如果您尝试使用博客页面 GOTO 仪表板 > 设置 > 并从选择菜单中删除帖子页面 :)

                                  【讨论】:

                                    【解决方案25】:

                                    模板下拉菜单现在移至页面部分,位于静态和可见性以及永久链接下拉菜单之间。但是,如果您将自定义文件命名为

                                    ,您将能够看到它

                                    page-Yourfilename.php

                                    并在文件顶部添加注释

                                    <?php
                                     /*
                                       Template Name: YOUR TEMPLATE NAME     
                                     */
                                    ?>
                                    

                                    【讨论】:

                                      猜你喜欢
                                      • 1970-01-01
                                      • 1970-01-01
                                      • 1970-01-01
                                      • 1970-01-01
                                      • 1970-01-01
                                      • 2019-03-08
                                      • 2017-06-09
                                      • 1970-01-01
                                      • 1970-01-01
                                      相关资源
                                      最近更新 更多