Support » Plugins » Get a Page Template outstide the loop

  • Resolved Accordo


    Hello everyone.
    I have an homepage with javascript slide-tabs that contains for each tab subpages from a certain parent page. All works very well with get_posts but when one of these subpages has a template it isn’t displayed.
    This is my code to call the subpages of a parent page:

    $args = array(
        'post_type' => 'page',
        'numberposts' => -1,
        'post_status' => null,
        'post_parent' => '934',
        'order' => ASC,
        'orderby' => date
     $subpages = get_posts($args);
     foreach($subpages as $post) :
         <div class="tabs-content">
            <?php the_content(); ?>
     <?php endforeach; ?>

    In this way i get the correct content from a page but obviously not his page template.
    I tried to use:

    <?php if (is_page_template( 'template-name.php' )) : ?>

    I can’t figure out. Please someone knows a solution?

    Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)
  • No one has a solution?



    Forum Moderator

    what are you trying to achieve?

    display some pages different than others?
    or display whatever you have programmed into the page template, when the respective page is called in your foreach loop?

    page templates are obviously there to display a full page (header and all), not just the page content within some other loop.

    you can find out which template the page (within your foreach loop) is using:
    echo get_post_meta( $post->ID, '_wp_page_template', true );

    you might be able to use this information to call the core code of the respective page template instead of:

    <div class="tabs-content">
            <?php the_content(); ?>

    please post a link to your site to illustrate what you have so far; and paste the code of the respective page template(s) into a and post the link to it here.

    to get you any help with this might be beyond the possibilities of the forum.

    Great! Your suggestion helps me very much!
    I’ve find this post:

    In a comment there is what I’m looking for. If the page template is page-right-col.php show the content and a right sidebar, if not show only the content:

    <?php if (get_post_meta($post->ID,'_wp_page_template',true) == 'page-right-col.php') : ?>
    			<?php the_content(); ?>
    			<?php include (TEMPLATEPATH . "/sidebar-right.php"); ?>
    <?php else : ?>
    			<?php the_content(); ?>
    <?php endif; ?>

    Thank you!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Get a Page Template outstide the loop’ is closed to new replies.