如何通过插件包含存档模板文件

时间:2014-12-03 12:11:42

标签: wordpress custom-taxonomy

我已通过插件注册了自定义分类wfa_book_genres,此分类的slug名称为genres

现在我想在插件文件夹中包含我的自定义分类的归档模板。我尝试使用下面的示例代码,但是当转到该归档术语时它显示完全空白。我不知道如何解决这个问题。我真的被困在这里:

add_filter('template_include', 'wfa_taxonomy_template');
function wfa_taxonomy_template( $template ){

 /*
  // if wfa_book_genres taxonomy
  if( is_tax('wfa_book_genres')){
    $template = plugin_dir_url(__FILE__ ).'taxonomy-wfa_book_genres.php';
   }
  */

  // if wfa_book_genres taxonomy slug
  if( is_tax('genres')){
    $template = plugin_dir_url(__FILE__ ).'taxonomy-wfa_book_genres.php';
  }  
  return $template;
 }

1 个答案:

答案 0 :(得分:0)

使用 dirname 更改 plugin_dir_url

    $template = dirname(__FILE__ ).'taxonomy-wfa_book_genres.php';