供全球使用的自定义页面模板,不要显示在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 );

来源:

https://www.srcmini02.com/64937.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_37370.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?