Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a page which has a jquery tab function to output the list of pages that are the children of this page (Bio, Archives, Contact).

However I am trying to make a conditional in the foreach loop to no avail.

<?php // get_posts function: http://codex.wordpress.org/Template_Tags/get_posts#Examples
$args = array( 
    'paged' => $paged,
    'post_type' => 'page',
    'post__in' => array( 3, 4, 5, 6 ), /* Bio, Client, Archives, Contact */
    'order' => 'ASC'
);
$myposts = get_posts( $args ); ?>

    <ul class="tablinks"> 
        <?php foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
            <li id="page-<?php global $post; echo $post->post_name; ?>">
                <a href="#<?php global $post; echo $post->post_name; ?>"><?php the_title(); ?></a>
            </li> 
        <?php endforeach;  ?>
    </ul>

    <?php foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
        <div class="tabcontents" id="<?php global $post; echo $post_slug=$post->post_name; ?>">
            <?php the_content(); ?>
            <!-- If this query is the Archives query, I would like to show thumbnails from this page's custom fields -->
            <?php edit_post_link("Edit"); ?>
        </div>
    <?php endforeach;  ?>

<?php wp_reset_postdata();?>

Basically, I would like to output the featured image of the children pages under Archives for when user views the Archives tab. I tried using this inside the foreach loop but it didn't work:

<?php if ( is_page( 5 ) || is_page('Archives') ) {
    echo 'Show me!';
} ?>

Can anyone help?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

I'm not sure I fully understand your question, but I wonder if you mean:

if( 5 == $post->ID 
    || 'archive' === mb_strtolower( $post->post_title ) 
    || 'archive' === $post->post_name )
{
    echo 'Show me';
}

when you generate the HTML for the tabs.

ps: If you check the source of is_page() you will see that it returns $wp_query->is_page( $page ), where it uses the global $wp_query object. So it's mainly used for main queries but not sub queries.

share|improve this answer
<?php // get_posts function: http://codex.wordpress.org/Template_Tags/get_posts#Examples
$args = array( 
    'paged' => $paged,
    'post_type' => 'page',
    'post__in' => array( 3, 4, 5, 6 ), /* Bio, Client, Archives, Contact */
    'order' => 'ASC'
);
$myposts = get_posts( $args ); ?>

    <ul class="tablinks"> 
        <?php foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
            <li id="page-<?php global $post; echo $post->post_name; ?>">
                <a href="#<?php global $post; echo $post->post_name; ?>"><?php the_title(); ?></a>
            </li> 
        <?php endforeach;  ?>
    </ul>

    <?php foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
        <div class="tabcontents" id="<?php global $post; echo $post_slug=$post->post_name; ?>">
            <?php the_content(); ?>
            <?php if($post->ID=='5'){ //output featured image } ?>
            <!-- If this query is the Archives query, I would like to show thumbnails from this page's custom fields -->
            <?php edit_post_link("Edit"); ?>
        </div>
    <?php endforeach;  ?>

<?php wp_reset_postdata();?>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.