在插件中添加自定义帖子类型分类模板


WordPress: Adding a custom post type taxonomy template in plugin

我已经创建了一个名为"accommodation"的自定义帖子类型,并使用文件"taxonomy-accommodation-categories.php"为它创建了一个名为"categories"的分类法——这在我的WordPress主题中工作得很好。

但是我想在一个单独的插件中添加这个,有人知道我怎么能做到这一点吗?

感谢您的帮助。

我想这就是你要找的。https://gist.github.com/vishalbasnet23/4cf739624ba3b75e75d8

wordpress codex有关于如何做到这一点的说明,https://codex.wordpress.org/Plugin_API/Filter_Reference/single_template

之前发布的github链接也有相同的东西,但更多的解释

这是必须的:


add_filter('template_include', 'taxonomy_template');
function taxonomy_template( $template ){
if( is_tax('accommodation-categories')){
    $template = BASE_DIR .'/templates/taxonomy-accommodation-categories.php';
}  
return $template;
}