return FALSE; $r = well_tag_thread__update(array('id' => $id), $update); return $r; } function well_tag_thread_find($tagid, $page, $pagesize) { $arr = well_tag_thread__find(array('tagid' => $tagid), array('id' => -1), $page, $pagesize); return $arr; } function well_tag_thread_find_by_tid($tid, $page, $pagesize) { $arr = well_tag_thread__find(array('tid' => $tid), array(), $page, $pagesize); return $arr; } ?>customization - For custom templates, is it better to use `template_include` or `type_template`?
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

customization - For custom templates, is it better to use `template_include` or `type_template`?

programmeradmin0浏览0评论

I saw a lot of questions about including custom views in Wordpress (I mean custom templates). There were many answers. Some people recommend using template_include and others recommend using type_template

My question is, which is better for working with custom templates? What are the pros and cons of both solutions?

I saw a lot of questions about including custom views in Wordpress (I mean custom templates). There were many answers. Some people recommend using template_include and others recommend using type_template

My question is, which is better for working with custom templates? What are the pros and cons of both solutions?

Share Improve this question asked May 24, 2020 at 14:52 kanlukaszkanlukasz 5448 silver badges24 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 2

{type}_template is a filter inside the get_query_template function. That function is called by a series of functions called get_home_template, get_category_template and so on. It allows you to very specifically target templates.

You can see it in action in template-loader.php, where the $tag_templates variable is defined, binding conditions like is_home, is_category and so on to the functions. Depending on the condition the function is then executed on the line where it says $template = call_user_func( $template_getter );.

A bit further on in the file you see the template_include filter. This is the last possibility to change the template before it is actually loaded. This means anything you may have done with {type}_template can be overruled here.

So, if you have full control over your install, the semantically most correct way would be to use {type}_template, because that filter is meant to keep track of template changes under specific circumstances. It would keep your code more readable.

However, if you want to make sure plugins are not overruling your {type}_template filter, you would opt for template_include.

发布评论

评论列表(0)

  1. 暂无评论