要显示子页面的缩略图+标签+标题,我需要做什么?
[缩略图]
[标题]
[标签]
谢谢
编辑:这很好,但只显示拇指+标题。。。添加标签应该不会太困难:
<?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;
?>
最合适的回答,由SO网友:Chip Bennett 整理而成
假设您已经启用了对静态页面的帖子缩略图和帖子标记的支持,我将使用WP_Query()
要构建查询,请执行以下操作:
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();
请注意,我没有包括任何故障保护,例如检查
has_post_thumbnail()
, 等