2017-11-18 292 views
0

我剛剛在我的WP主題文件夾中添加了一個新的自定義模板文件。 這個新的模板開始喜歡我的人的模板文件:Wordpress頁面模板不會出現在模板下拉列表中

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

Strangly,這個新的模板不內模板下拉列表中顯示的管理頁面編輯內。

它似乎有一個WP緩存問題或類似的東西...我試圖清除我的瀏覽器的Cookie和緩存,清除我的服務器緩存等等,但它不起作用。

回答

1

經過一個多小時在網上搜索和測試很多東西更多,我發現我需要改變我的主題版本,讓WP知道新的文件結構(內的style.css):

/* 
Theme Name: My Theme Name 
Version: 1.0.0 
*/ 

TO

/* 
Theme Name: My Theme Name 
Version: 1.0.1 
*/ 

最後和它的工作! 希望這將幫助別人;)

+0

我似乎能夠創建一個模板,併成功地使其出現在相關的下拉菜單中,沒有需要引用任何文件版本。有興趣知道是否有其他人遇到過這個問題。 – Craig

+0

我從來沒有聽說過這種情況,官方WordPress網站甚至展示瞭如何創建一個像這樣的全局模板<?php/*模板名稱:示例模板* /?>沒有提及任何地方的主題版本... –

+0

對不起,一些信息丟失......它發生在最後一次WP更新到4.9版本。在此版本之前,我從未遇到過這個問題。另外,主題版本位於style.css中,而不是在每個模板文件中聲明。謝謝! –

0

如果您安裝了WP-CLI,嘗試運行wp cache flush

你可以把這個代碼到你的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'); 

參考:Fix for theme template file caching https://gist.github.com/westonruter/6c2ca0e5a4da233bf4bd88a1871dd950

:)