首页 视频课程 WordPress开发文档文件结构及模板加载 模板判断

模板判断

2020-10-26 / 3893阅

WordPress模板系统可让您过滤层次结构。可以动态的修改模板的加载顺序

以下是模板层次结构中所有可用过滤器的列表:

embed_template
404_template
search_template
frontpage_template
home_template
privacypolicy_template
taxonomy_template
attachment_template
single_template
page_template
singular_template
category_template
tag_template
author_template
date_template
archive_template
index_template 

可以与include()或require()一起使用以检索路径。

if ( '' !== get_query_template( '404' ) ) {
include( get_query_template( '404' ) );
}
if ( '' != get_404_template() ) {
include( get_404_template() );
}

下面的代码可以在主题或者插件中使用,改变分类法为 links_list的模板加载顺序,调用自己设置的模板文件。

//截获自定义分类法页面-重写模板文件
add_filter('taxonomy_template','youran_links_list',10,3);
function youran_links_list($taxonomy){
       if (is_tax('links_list')) {
              $tax_template = dirname(  __FILE__  ) . '/taxonomy.php';
       }
       return $tax_template;
}
 

阅读文章或者观看视频过程中有任何问题,请下方留言或者联系我Q248758228

大家谈论
    我的见解
    目录