wp query - list pages using page.php and NOT page-{slug}.php

I made a view templates for specific slugspage1-220 use page.phpcontact uses page-contact.phpservice usespage-ser

I made a view templates for specific slugs

  • page1-220 use page.php
  • contact uses page-contact.php
  • service uses page-service.php

Now I want to list the pages with their templates on a "overview" page with page-overview.php template... .

I tried this:

<?php $args = array(
'post_type' => 'page', /* or just 'post' */
'posts_per_page' => -1,

 );
$the_query = new WP_Query( $args );
$i=1;
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
    $the_query->the_post();
    echo '<p>'; 
    echo $i . '. ';
    the_title();
    echo ' - ';
    echo get_page_template(); 
    echo '</p>';
    $i++;
}
wp_reset_postdata();
} ?>

get_page_template() allways returns the path to page-overview.php.

Wonder what I am missing here. I wonder if there is a way to get a list of ids, using the page.php template.

Many thanks in advance

I made a view templates for specific slugs

  • page1-220 use page.php
  • contact uses page-contact.php
  • service uses page-service.php

Now I want to list the pages with their templates on a "overview" page with page-overview.php template... .

I tried this:

<?php $args = array(
'post_type' => 'page', /* or just 'post' */
'posts_per_page' => -1,

 );
$the_query = new WP_Query( $args );
$i=1;
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
    $the_query->the_post();
    echo '<p>'; 
    echo $i . '. ';
    the_title();
    echo ' - ';
    echo get_page_template(); 
    echo '</p>';
    $i++;
}
wp_reset_postdata();
} ?>

get_page_template() allways returns the path to page-overview.php.

Wonder what I am missing here. I wonder if there is a way to get a list of ids, using the page.php template.

Many thanks in advance

Share Improve this question asked Aug 14, 2019 at 18:28 Friedrich SieverFriedrich Siever 2581 silver badge12 bronze badges 1
  • 1 get_page_template() returns the current page template. you need get_page_template_slug( $id ) to get the template of $id post. – idpokute Commented Aug 14, 2019 at 18:56
Add a comment  | 

1 Answer 1

Reset to default 1

I believe you need to use get_template_part, but you need to request the get_page_template_slug first.

So that would look like:

get_template_part( get_page_template_slug( get_the_ID() ) );

in lieu of

echo get_page_template();

And no need to echo it, it returns the template already printed.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745241147a4618188.html

相关推荐

  • wp query - list pages using page.php and NOT page-{slug}.php

    I made a view templates for specific slugspage1-220 use page.phpcontact uses page-contact.phpservice usespage-ser

    8小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信