I’m not entirely certain I understand what you mean but whenever a Page Template is set WordPress also sets postmeta with a specific key and value. The key is called _wp_page_template
and the value holds the template location relative to the theme. So you could do this:
$pages_with_templates = new WP_Query( array(
'post_type' => 'page',
'posts_per_page' => 20,
'meta_key' => '_wp_page_template',
) );
This will return a list of pages that have templates, you could narrow it down even more by supplying a value:
$pages_with_this_template = new WP_Query( array(
'post_type' => 'page',
'posts_per_page' => 20,
'meta_key' => '_wp_page_template',
'meta_value' => 'template-fullwidth.php',
) );
Now, when I said relative to the theme I mean that if you are using a sub-directory such as: theme-name/page-templates/template-fullwidth.php
the postmeta value will hold: pages-templates/template-fullwidth.php
.
There’s also a conditional to test if the current page is using a specific template:
if( is_page_template( 'template-fullwidth.php' ) ) { ... }
Finally, if you’re using the body_class()
function – WordPress will assign a specific class based on the template to the body tag which you could target if you feel so inclined.