So I’m doing a query like this:
$the_query = new WP_Query( array( 'meta_key' => 'homepage', 'meta_value' => 'yes',
'post_type' => 'page', 'orderby' => 'modified', 'posts_per_page' => 1 ) );
To get a single page with a specific key value, how do I get the page template from a query like this, if it has one?
Thank you!
This should do the trick for you. This shows what template file is stored in
post_meta
, if one has been selected in the admin panel:$template_name = get_post_meta( $the_query->post->ID, '_wp_page_template', true );
If you want to see if the page is the homepage, use
is_home()
oris_front_page()
.If you want to see what files are generating the page, use this in your functions.php:
I use it in
footer.php
like this:One quick method I use is the WordPress global
$template
. I output it in the page source as well.Just before the closing
</body>
tagglobal $template;
echo '<!-- the template is:' . $template . '-->';
or as a function: