Wordpress页面模板不显示在模板下拉列表中

Wordpress页面模板不显示在模板下拉列表中,wordpress,templates,caching,themes,admin,Wordpress,Templates,Caching,Themes,Admin,我刚刚在我的WP主题文件夹中添加了一个新的自定义模板文件。 此新模板开始时与我的其他模板文件类似: <?php /* Template Name: My Template Name */ 经过一个多小时的网络搜索和测试,我发现我需要更改我的主题版本,让WP知道新的文件结构(inside style.css): 到 终于成功了! 希望它能帮助其他人;) 如果安装了WP-CLI,请尝试运行WP缓存刷新或 您可以将此代码放入functions.php中 function fix_templat

我刚刚在我的WP主题文件夹中添加了一个新的自定义模板文件。 此新模板开始时与我的其他模板文件类似:

<?php
/*
Template Name: My Template Name
*/

经过一个多小时的网络搜索和测试,我发现我需要更改我的主题版本,让WP知道新的文件结构(inside style.css):

终于成功了!
希望它能帮助其他人;)

如果安装了WP-CLI,请尝试运行
WP缓存刷新

您可以将此代码放入functions.php中

function fix_template_caching( WP_Screen $current_screen ) { if ( ! in_array( $current_screen->base, array( 'post', 'edit', 'theme-editor' ), true ) ) { return; } $theme = wp_get_theme(); if ( ! $theme ) { return; } $cache_hash = md5( $theme->get_theme_root() . '/' . $theme->get_stylesheet() ); $label = sanitize_key( 'files_' . $cache_hash . '-' . $theme->get( 'Version' ) ); $transient_key = substr( $label, 0, 29 ) . md5( $label ); delete_transient( $transient_key ); } add_action( 'current_screen', 'fix_template_caching' ); 函数修复\u模板\u缓存(WP\u屏幕$current\u屏幕){ if(!in_数组($current_screen->base,array('post','edit','theme editor'),true)){ 回来 } $theme=wp_get_theme(); 如果(!$主题){ 回来 } $cache\u hash=md5($theme->get\u-theme\u-root()。/。$theme->get\u-stylesheet()); $label=sanitize_key('files_uu'.$cache_hash.-'.$theme->get('Version'); $transient_key=substr($label,0,29).md5($label); 删除临时($transient\u key); } 添加操作(“当前屏幕”、“修复模板缓存”); 参考:


:)

对我来说,解决方案是更改丢失模板的文件权限。由于某种原因,当我上传文件时权限不正确,但在将其chmod权限更改为755后,模板按预期出现在下拉列表中


参考:

我似乎能够创建一个模板,并成功地将其显示在相关的下拉菜单中,而无需参考任何文件版本。我很想知道是否有人遇到过这种情况。我从来没有听说过这种情况,官方WordPress网站甚至展示了如何创建这样一个全局模板,没有提到任何地方的主题版本…抱歉,缺少一些信息。。。它发生在上一次WP更新到4.9版本时。在这个版本之前,我从未遇到过这个问题。此外,主题版本在style.css中,而不是在每个模板文件中声明。谢谢
/*
Theme Name: My Theme Name
Version: 1.0.1
*/ 
function fix_template_caching( WP_Screen $current_screen ) { if ( ! in_array( $current_screen->base, array( 'post', 'edit', 'theme-editor' ), true ) ) { return; } $theme = wp_get_theme(); if ( ! $theme ) { return; } $cache_hash = md5( $theme->get_theme_root() . '/' . $theme->get_stylesheet() ); $label = sanitize_key( 'files_' . $cache_hash . '-' . $theme->get( 'Version' ) ); $transient_key = substr( $label, 0, 29 ) . md5( $label ); delete_transient( $transient_key ); } add_action( 'current_screen', 'fix_template_caching' );