How can I list all pages with their templates?

https://codex.wordpress.org/Function_Reference/get_page_template_slug

a basic query to get all pages, sorted by title, then output page title and template file name:

$args = array(
    'post_type' => array( 'page' ),
    'order' => 'ASC',
    'orderby' => 'title'
    );
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
    while ( $the_query->have_posts() ) {
        $the_query->the_post();
        echo '<p>'; 
        the_title();
        echo ' - ';
        echo get_page_template_slug(); 
        echo '</p>';
    }
    wp_reset_postdata();
}

Leave a Comment