Template Dropdown not showing up within Wordpress

2019-03-12 15:51发布

问题:

I am working on a Wordpress-based project, and I just added a new template to the installation by uploading a template file. I was creating a new page that will use my new template, when suddenly, the "Template" dropdown in the "Page Attributes" box is gone.

I am using Wordpress 3.0.1.

Update: I saw a site which told me to revert to the default template, and back to my custom template. Apparently it worked, but I am still baffled on what triggers this bug. Also, any additional knowledge or pointers on this bug would be a great help since my job requires me to patch this (and possibly submit the bug fix to Wordpress). Thanks!

回答1:

If you have disabled or removed the style.css from the template directory then also it will not work.

So there must be the style.css on template directory then the templates directory will be shown. When you try to remove the style.css from the template directory or using style.css from css folder, then you must be put one style.css on template directory.

Thanks



回答2:

Morichika is spot on. I had the same problem, but then it sorted itself out by doing:

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


回答3:

I have found a different solution for this. I reactivated my custom theme but then problem persisted.. then in the top most section of the code for the custom page template where it actually defines the name of the template like this:

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

I did this:

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

Then refreshed the admin panel and it appeared.Seems a bit weird but it worked for me. Feel happy to share this.



回答4:

Put style.css in your theme directory, instead of the css folder. Or

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

There must not space between "Template Name:".



回答5:

I managed to fix this by making sure the style.css in the theme root contained the theme comments. I accidentally deleted mine and it removed the templates dropdown.

https://codex.wordpress.org/Theme_Development#Theme_Stylesheet



回答6:

I had the exact same problem with WordPress 3.2.1. I added a new template and the menu disappeared from the page add/edit screen. The solution was to switch back to the default twentyeleven theme end then right back to my custom theme. The templates drop-down began appearing again.

BTW, you said "revert to the default template, and back to my custom template" but I'm pretty sure you meant theme. I'm guessing where you saw this was here:

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

Looks like this bug has existed for a couple of years at least. I filed a report: http://core.trac.wordpress.org/ticket/18324



回答7:

I know is super late for this question, but I fix it adding

Version: 0.1 alpha

in the comments of the themeFolder/style.css

This is my style.css complete for my theme

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

I hope someone find this useful



回答8:

I had this problem a while back and found one janky solution after a lot of search--sometimes switching to another theme in your install and then switching back to you primary theme will make your templates appear. I know that sounds weird, but worked for me for a while.



回答9:

I've had this problem for two days. This forum and a couple of tests later did the work. Here is what was missing for my part.


Be sure that there is a style.css in your theme folder.

The style.css must have a valid comment section at the top of the file. This means at least this:

/*!
Template: your-theme
*/

If you're using SASS or LESS, make sure that you have a "!" just after declaring your comment. It's to prevent SASS or LESS to delete your comment section.

To be sure that everything is settled fine. You may go to "Appearance > Themes". After the listing of themes, if there is nothing, than everything should be fine. Otherwise, it'll be written "Broken Themes" and you'll still have some issues to solve.



回答10:

I tried many of the suggested answers. None worked in my case.

A possible reason for the Template Dropdown not showing is a missing index.php in your Theme folder.

Just create an empty one, in case your hierarchy does not need one. But the existance of that file enables the option to choose the page template and suppresses an error message in the Choose-Theme page btw



回答11:

I was just facing the same issue so, the problem is in spacing between 'Template Name' and that colon.

/*
  Template Name: template-name
*/

Make sure there is no spacing before the colon.



回答12:

I found the root of the problem. It is the style.css file inside the theme root.

  1. It must be in "UNIX encoding".

  2. It must have all comments with "Theme Name", "Version", etc.



回答13:

Jack Nicholson was right! You need to make sure your style.css contains the full comment. Example below:

Previously mine was:

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

Then I changed it to the below and now I can see all my templates.

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


回答14:

Please set properly you style.css file specially if you are working on child-theme

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



回答15:

This below is work for me and show template option in page attributes.Just place .php file in theme root folder.

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


回答16:

sass had deleted the content in my child style.css. The template drop down shows again once I added back the comments. /* Theme Name: Sometheme Child Description: Child theme for Sometheme. Template: sometheme Version: 1.1 Text Domain: sometheme-child */