php 显示/列出具有特定模板的所有页面

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 显示/列出具有特定模板的所有页面相关的知识,希望对你有一定的参考价值。

<?php 
  $args = array(
    'post_type' => 'page',
    'posts_per_page' => -1,
    'meta_query' => array(
        array(
            'key' => '_wp_page_template',
            'value' => 'template--location.php' // template file name
        )
    )
);
$the_pages = new WP_Query( $args );

if( $the_pages->have_posts() ){
    while( $the_pages->have_posts() ){
        $the_pages->the_post();
        the_title();
    }
} else {
    echo "<h1>None found!</h1>";
}
wp_reset_postdata(); ?>

以上是关于php 显示/列出具有特定模板的所有页面的主要内容,如果未能解决你的问题,请参考以下文章