WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Get a Page Template outstide the loop (4 posts)

  1. Accordo
    Member
    Posted 3 years ago #

    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:

    <?php
    $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) :
        setup_postdata($post);
     ?>
    
         <div class="tabs-content">
            <?php the_content(); ?>
          </div>
    
     <?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.

  2. Accordo
    Member
    Posted 3 years ago #

    No one has a solution?

  3. alchymyth
    Forum Moderator
    Posted 3 years ago #

    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(); ?>
          </div>

    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 http://pastebin.com/ and post the link to it here.

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

  4. Accordo
    Member
    Posted 3 years ago #

    Great! Your suggestion helps me very much!
    I've find this post: http://archive.extralogical.net/2007/06/detect-template/

    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!

Topic Closed

This topic has been closed to new replies.

About this Topic