[wp-hackers] Template Redirection

Ryan Boren ryan at boren.nu
Tue Aug 24 17:22:43 UTC 2004


On Tue, 2004-08-24 at 12:17 -0500, Seth Thomas Rasmussen wrote:
> Great idea! I hope it makes it in the next release. I've wanted such a
> functionality since day one.

It's already in CVS.  Unless someone points out nasty flaws that cannot
be addressed, I imagine it will stay.    Those of you with testbeds
running CVS, please try this new feature and do your best to break it.

Ryan

> -----Original Message-----
> From: hackers-bounces at wordpress.org
> [mailto:hackers-bounces at wordpress.org]On Behalf Of Ryan Boren
> Sent: Tuesday, August 24, 2004 12:08 PM
> To: WordPress Hackers
> Subject: [wp-hackers] Template Redirection
> 
> 
> In CVS is some experimental code which can load different templates for
> different query types, all from index.php.  For example, if the query is
> for a category, we check to see if wp-content/category.php exists.  If
> so, we use it instead of index.php.  The same is true of authors, single
> posts, dates, archives, and so forth.  If you do not provide alternative
> templates in wp-content, index.php behaves the same way it ever has.
> 
> All of this redirection is done without having to change the rewrite
> rules.  Everything still goes through index.php.  This should make it
> much easier for those wanting to style their post pages or their search
> pages or what-have-you via separate templates.  You still have the
> option of styling everything through index.php, which is made easier by
> the is_single(), is_category(), is_author(), is_archive(), etc.
> functions.
> 
> Take a look at wp-blog-header.php in CVS and let me know what you think.
> Try it out, kick the tires, provide feedback.  Excerpted below are the
> relevant bits from wp-blog-header.php.  This can be expanded to other
> query types.  Let me know what would be useful to you.
> 
> // Template redirection
> if (is_single() && (! isset($wp_did_single)) &&
>     file_exists(ABSPATH . 'wp-content/single.php')) {
>   $wp_did_single = true;
>   include(ABSPATH . 'wp-content/single.php');
>   exit;
> } else if (is_page() && (! isset($wp_did_page)) &&
> 	    file_exists(ABSPATH . 'wp-content/page.php')) {
>   $wp_did_page = true;
>   include(ABSPATH . 'wp-content/page.php');
>   exit;
> } else if (is_category() && (! isset($wp_did_category)) &&
> 	   file_exists(ABSPATH . 'wp-content/category.php')) {
>   $wp_did_category = true;
>   include(ABSPATH . 'wp-content/category.php');
>   exit;
> } else if (is_author() && (! isset($wp_did_author)) &&
> 	   file_exists(ABSPATH . 'wp-content/author.php')) {
>   $wp_did_author = true;
>   include(ABSPATH . 'wp-content/author.php');
>   exit;
> } else if (is_date() && (! isset($wp_did_date)) &&
> 	   file_exists(ABSPATH . 'wp-content/date.php')) {
>   $wp_did_date = true;
>   include(ABSPATH . 'wp-content/date.php');
>   exit;
> } else if (is_archive() && (! isset($wp_did_archive)) &&
> 	   file_exists(ABSPATH . 'wp-content/archive.php')) {
>   $wp_did_archive = true;
>   include(ABSPATH . 'wp-content/archive.php');
>   exit;
> } else if (is_search() && (! isset($wp_did_search)) &&
> 	   file_exists(ABSPATH . 'wp-content/search.php')) {
>   $wp_did_search = true;
>   include(ABSPATH . 'wp-content/search.php');
>   exit;
> } else if (is_feed() && $pagenow != 'wp-feed.php') {
>   include(dirname(__FILE__) . '/wp-feed.php');
>   exit;
> } else if ($pagenow != 'wp-trackback.php' && $tb == 1) {
>   include(dirname(__FILE__) . '/wp-trackback.php');
>   exit;
> }
> 
> 
> 
> _______________________________________________
> hackers mailing list
> hackers at wordpress.org
> http://wordpress.org/mailman/listinfo/hackers_wordpress.org
> 
> 
> _______________________________________________
> hackers mailing list
> hackers at wordpress.org
> http://wordpress.org/mailman/listinfo/hackers_wordpress.org




More information about the hackers mailing list