[wp-trac] [WordPress Trac] #18151: Option to return string false for locate_template()

WordPress Trac wp-trac at lists.automattic.com
Mon Jul 18 11:36:08 UTC 2011


#18151: Option to return string false for locate_template()
-------------------------+------------------------------
 Reporter:  griffinjt    |       Owner:
     Type:  enhancement  |      Status:  reopened
 Priority:  normal       |   Milestone:  Awaiting Review
Component:  Template     |     Version:  3.2.1
 Severity:  normal       |  Resolution:
 Keywords:  needs-patch  |
-------------------------+------------------------------

Comment (by griffinjt):

 Here is sample code that I am using:


 {{{
 add_action( 'template_redirect', 'custom_page_template_setup', 9 );
 function custom_page_template_setup() {

         global $options, $post, $classes;

         if ( $options['default_page_layout'] == 'Full Width' && is_page()
 ) {
                 if ( get_post_meta( $post->ID, '_wp_page_template', true )
 == 'default' ) {
                         $default_template = add_filter( 'body_class',
 'custom_page_body_class' );
                         $default_template = locate_template( array( 'full-
 width-template.php' ), true );
                         exit( $default_template );
                 }
         }
 }}}

 A user can choose to have a default page template be set for any page that
 is created. This function takes that into account, checks that no page
 template has been set for any individual page, and if not, sets the
 template for the one they specified in the options area. Because
 locate_template() returns the filename string, it gets outputted at the
 very end of the page, right before the closing </body> tag. Now
 load_template() can get around this, but then limits the end user to
 whatever templatepath I specify. locate_template() would be preferred
 because it is more forward and would allow for the end user to create
 their own version of the template and use it throughout their site.

 I hope this explains what I am talkin about. If there is another way
 besides template_redirect, then by all means let me know...but the way I
 see it, this is a pretty good way of doing it.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/18151#comment:5>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list