[wp-hackers] template_redirect vs. single_template vs. other? (was $wp_rewrite->add_permstruct() vs. add_rewrite_rule())

Mike Schinkel mikeschinkel at newclarity.net
Thu Dec 10 02:42:12 UTC 2009


On Dec 8, 2009, at 2:54 PM, Otto wrote:
> Well, it depends on what exactly you want to do. Hard to say without
> knowing that, precisely.
> 
> You'd use template_loader when you want to bypass the templates system
> altogether. Basically, templates are all the files in the theme
> hierarchy. Single.php, page,php, category-x.php, archive.php, etc. All
> these templates can be overriden directly, of course, so
> template_loader is for when you want to go completely outside the
> norm.
> 
> For the *_templates, the actual filter is performed on
> {$type}_template, where type is the argument to get_query_template. So
> you can override any of them. 404, author, archive, date, paged,
> search, single, attachment, and any mime type attachments (text/plain
> would be "text" and "plain" and "text_plain", image/gif would be
> "image", then "gif", then "image_gif", etc...). So it's pretty wide
> open there.
> 
> Which branch of the hierarchy is examined depends on the contents of
> the $wp_query. If is_single gets set (because you got a single post),
> then it goes to the single branch first, etc.
> 
> In essence, you need to determine three things.
> 1. What do the URLs look like?
> 2. What posts should be pulled?
> 3. What template file should be loaded?
> 
> Each of these will be handled separately, however some of them can be
> skipped or made simpler if there's already support in WordPress for
> that specific case. In the case of "pulling one and only one post",
> then wp_query can already do that (by setting the %post_id%), and the
> single branch of the template hierarchy handles that just fine.

That is really, really good and awfully useful, and couldn't find anywhere else. 
Add to the Codex somewhere?

> In the case of pulling, say, custom post types, then it's a tad more
> complicated.

What about it is more complex?  I haven't found that yet.

-Mike


More information about the wp-hackers mailing list