[wp-trac] [WordPress Trac] #18750: specify post ID for is_page_template

WordPress Trac wp-trac at lists.automattic.com
Thu Sep 22 17:47:04 UTC 2011


#18750: specify post ID for is_page_template
------------------------------------+------------------------------
 Reporter:  billerickson            |       Owner:
     Type:  enhancement             |      Status:  new
 Priority:  normal                  |   Milestone:  Awaiting Review
Component:  General                 |     Version:
 Severity:  normal                  |  Resolution:
 Keywords:  has-patch dev-feedback  |
------------------------------------+------------------------------

Comment (by duck_):

 You re-patched and replied whilst I was writing this, but I'm going to put
 it in anyway since I wrote it. It looks like you got what I meant, but
 note that my example is much simpler as it isn't written to work in the
 loop without an ID.

 ---

 Sorry, didn't really answer you :( Pretty much starting again...

 From your two use case bullet points it sounds like you just want to do
 something like:

 {{{
 if ( get_post_meta( $current_id, '_wp_page_template', true ) ==
 get_post_meta( $parent_id, '_wp_page_template', true ) )
     // do some stuff as the templates are the same
 }}}

 and

 {{{
 if ( 'some_template' == get_post_meta( $id, '_wp_page_template', true ) )
     // add metaboxes as the correct template is set
 }}}

 I then suggested the possibility of a new function which would just be a
 wrapper for the get_post_meta call so that you don't have to be specifying
 a core meta key. (Foolishly I managed to suggest a new function that
 already exists!) So you would end up taking the above examples and
 replacing `get_post_meta( $id, '_wp_page_template', true )` with
 `possible_new_function( $id )`. Where:

 {{{
 function possible_new_function( $id ) {
     return get_post_meta( $id, '_wp_page_template', true );
 }
 }}}

 or something similar.

 Why didn't I think it should be a mod to `is_page_template()`? Because
 that is specifically for determining "whether currently in a page
 template" with the ability to specify a certain template. It's not a more
 abstract function for querying a page's template.

 Hope that makes sense :) P.S. All code is untested.

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


More information about the wp-trac mailing list