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.

What do I need to do to display thumbnail + tags + title of a child page?

[ Thumbnail ]

[ Title ]

[ Tags ]

Thanks!

EDIT: Well this work, but only showing thumbs+title... it shouldnt be too difficult to add the tags:

    <?php
    $child_pages = $wpdb->get_results("SELECT *    FROM $wpdb->posts WHERE post_parent = ".$post->ID."    AND post_type = 'page' ORDER BY menu_order", 'OBJECT');    ?>
    <?php if ( $child_pages ) : foreach ( $child_pages as $pageChild ) : setup_postdata( $pageChild ); ?>
    <div class="child-thumb">
     <a href="<?php echo  get_permalink($pageChild->ID); ?>" rel="bookmark" title="<?php echo $pageChild->post_title; ?>"> <?php echo get_the_post_thumbnail($pageChild->ID, 'thumbnail'); ?></a><br />
     <a href="<?php echo  get_permalink($pageChild->ID); ?>" rel="bookmark" title="<?php echo $pageChild->post_title; ?>"><?php echo $pageChild->post_title; ?></a><br />
    </div>
    <?php endforeach; endif;
    ?>
share|improve this question
    
What have you tried already? –  Chip Bennett Jun 6 '12 at 19:06
    
I've added the 1st post with the code –  Phife Dawz Jun 6 '12 at 19:48
1  
Did you enable post-type support for post_tags, for Pages? –  Chip Bennett Jun 6 '12 at 19:53
    
Yupp! The tags works on pages, so no problem there! :) I tried to add <?php echo get_the_tags($pageChild->ID); ?>, but that generates the word Array on the parent page.. –  Phife Dawz Jun 6 '12 at 20:07
add comment

1 Answer

up vote 0 down vote accepted

Assuming that you've enabled support for both post thumbnails and post tags for static Pages, I would use WP_Query() to build your query, and do something like the following:

global $post;
$child_pages_query_args = array(
    'post_type'   => 'page',
    'post_parent' => $post->ID,
    'orderby'     => 'menu_order'
);

$child_pages = new WP_Query( $child_pages_query_args );

if ( $child_pages->have_posts() ) : while ( $child_pages->have_posts() ) : $child_pages->the_post();
    ?>
    <div class="child-thumb">
        <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a>
        <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
        <?php the_tags(); ?>
    </div>
    <?php
endwhile; endif;

// Be kind; rewind
wp_reset_postdata();

Note that I've not included any failsafes, such as checking for has_post_thumbnail(), etc.

share|improve this answer
    
Wonderful! Works great! –  Phife Dawz Jun 6 '12 at 21:12
    
Glad to help! Be sure to accept the answer, by clicking the checkmark beneath the voting buttons, if it solved your issue. :) –  Chip Bennett Jun 6 '12 at 21:16
add comment

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.