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="https://wordpress.stackexchange.com/questions/54394/<?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="https://wordpress.stackexchange.com/questions/54394/<?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;
?>
1 Answer
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="https://wordpress.stackexchange.com/questions/54394/<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a>
<a href="https://wordpress.stackexchange.com/questions/54394/<?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.