个性化阅读
专注于IT技术分析

供全球使用的自定义页面模板,不要显示在wordpress模板下拉菜单中

点击下载

我到处搜寻, 找不到。

现在, 你是我唯一的希望, 请帮助。

供全球使用的自定义页面模板, 当我为模板零件创建自定义页面时, 不会出现在wordpress模板下拉列表中。

My-theme / global_template.php工作

My-theme / template-parts / global_template.php工作

My-theme / template-parts / archive / global_template.php不起作用

如何使包含模板的模板部分内部的文件夹出现在页面属性->模板中?

自定义页面模板位置

这是global_template.php中的代码

自定义页面模板代码

如你所见, 没有测试模板。

页面属性

#1


你的问题是获取模板的功能的深度为1深度。因此你必须将文件放在主题根目录或第一个子文件夹中

核心函数get_post_templates()调用深度为1的get_files(), 并将其传递给扫描目录的函数scandir()。

你可以手动添加更多模板, 例如将add_filter中的{$ post_type}替换为要添加模板的帖子类型。例如页面。

/**
* @param array $post_templates Array of page templates.
* Keys are filenames, values are translated names.
*/
function extend_post_type_templates($post_templates, $this, $post, $post_type) {
    $post_templates['template-parts/archive/global_template.php'] = 'Name for this';
    return $post_templates;
}
add_filter( 'theme_{$post_type}_templates', 'extend_post_type_templates', 10, 4 );
赞(0)
未经允许不得转载:srcmini » 供全球使用的自定义页面模板,不要显示在wordpress模板下拉菜单中

评论 抢沙发

评论前必须登录!