the page template is setted via a meta field with the key '_wp_page_template'
. The value for this meta field is the php full file name of the template file, something like
'page-products.php'
so you can create a custom function to easyly get the page with a specific template using meta_key and meta_value param off get_pages
(or using a WP_Query
with 'meta_query'
argument):
get_pages_by_template( $template = '', $args = array() ) {
if ( empty($template) ) return false;
if ( strpos($template, '.php') !== (strlen($template) - 4) ) $template .= '.php';
$args['meta_key'] = '_wp_page_template';
$args['meta_value'] = $template;
return get_pages($args);
}
This function accepts as first (mandatory) argument the template and as second (optional) argument all the arguments of get_pages.
the template can passed with or without '.php' extension:
$pages = get_pages_by_template('page-products');
or
$pages = get_pages_by_template('page-products.php');
After that, you can use the page retrieved as you want: loop throu them and output some markup, create a custom widget that make use of the function, and so on...