【问题标题】:Wordpress page template dont appear inside Template Dropdown ListWordpress 页面模板不出现在模板下拉列表中
【发布时间】:2017-11-18 03:58:54
【问题描述】:

我刚刚在我的 WP 主题文件夹中添加了一个新的自定义模板文件。 这个新模板就像我的其他模板文件一样开始:

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

奇怪的是,这个新模板没有出现在管理页面编辑的模板下拉列表中。

似乎有 WP 缓存问题或类似问题...我已尝试清除浏览器的 cookie 和缓存,清除服务器缓存等等...但它不起作用。

【问题讨论】:

    标签: wordpress templates caching themes admin


    【解决方案1】:

    在网上搜索了一个多小时并测试了很多东西后,我发现我需要更改我的主题版本以让 WP 知道新的文件结构(在 style.css 中):

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

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

    终于成功了! 希望它会帮助别人;)

    【讨论】:

    • 我似乎能够创建一个模板并成功地使其出现在相关的下拉菜单中,而无需引用任何文件版本。很想知道其他人是否遇到过这个问题。
    • 我从来没有听说过这种情况,官方 WordPress 网站甚至展示了如何创建这样的全局模板 没有提到主题版本任何地方...
    • 抱歉,有些信息丢失了……它发生在上次 WP 更新到 4.9 版本时。在这个版本之前,我从来没有遇到过这个问题。此外,主题版本在 style.css 中,而不是在每个模板文件中声明。谢谢!
    【解决方案2】:

    如果您安装了 WP-CLI,请尝试运行 wp cache flush

    你可以把这段代码放到你的functions.php中

    功能修复模板缓存(WP_Screen $current_screen){ if ( ! in_array( $current_screen->base, array( 'post', 'edit', 'theme-editor' ), true ) ) { 返回; } $theme = wp_get_theme(); 如果(!$主题){ 返回; } $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($标签); 删除瞬态($瞬态键); } add_action('current_screen', 'fix_template_caching');

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

    :)

    【讨论】:

      【解决方案3】:

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

      参考:https://vanseodesign.com/wordpress/wp-page-templates-dropdown/

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-10-24
        • 2016-10-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多