【发布时间】:2022-06-30 05:54:59
【问题描述】:
正如标题所说,我正在创建一个 Sage 10 主题(我们不使用基岩)。这个网站需要一个自定义的“speaker”帖子类型,它还带有一个single-speaker.php页面来显示信息。所有这些功能都是在插件中编写的,但我无法让页面模板填充到主题中。
自定义帖子类型和元框确实有效,我也可以获取值。但是,single-speaker.php 页面将不起作用。我试过了:
add_filter('single_template', 'speaker_single_template');
function speaker_single_template($single) {
global $post;
/* Checks for single template by post type */
if ( $post->post_type == 'speaker' ) {
if ( file_exists( SPEAKER_PLUGIN_URL . '/templates/single-speaker.php' ) ) {
return SPEAKER_PLUGIN_URL . '/templates/single-speaker.php';
}
}
return $single;
}
我原以为这个过滤器会将模板页面推送到主题中,但事实并非如此。
Sage 使用刀片指令是否存在问题?我假设默认的 php 页面仍然可以工作。
template_redirect
hook orinit
hook. The reason for not working is that I think your plugin load after thesingle_template
hook or filter