2 回答

TA貢獻(xiàn)1789條經(jīng)驗(yàn) 獲得超8個(gè)贊
您可以創(chuàng)建自定義查詢,并且在該查詢中您可以根據(jù)條件更改參數(shù)。在循環(huán)內(nèi),您可以the_post_thumbnail()用來(lái)顯示帖子的特色圖片。
function wpb_list_child_pages() {
global $post;
ob_start();
$qargs = array(
'posts_per_page' => 10,
'post_type' => 'page',
'orderby' => 'menu_order',
);
if ( is_page() && $post->post_parent ) {
$qargs['post_parent'] = $post->post_parent;
} else {
$qargs['post_parent'] = $post->ID;
}
$the_query = new WP_Query( $qargs );
?>
<?php if ( $the_query->have_posts() ) : ?>
<ul class="list-unstyled">
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<li>
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<?php if ( has_post_thumbnail( ) ) : ?>
<?php the_post_thumbnail( 'post-thumbnail' ); ?>
<?php endif; ?>
</li>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
</ul>
<?php endif; ?>
<?php
$output = ob_get_contents();
ob_end_clean();
return $output;
}
add_shortcode( 'wpb_childpages', 'wpb_list_child_pages' );

TA貢獻(xiàn)2065條經(jīng)驗(yàn) 獲得超14個(gè)贊
最簡(jiǎn)單的方法是使用函數(shù)。編寫(xiě) WP_Query 以獲取子列表中的縮略圖圖像。它將作為 wp_list_pages 工作。
function wpb_list_child_pages() {
global $post;
if ( is_page() && $post->post_parent )
$child_pages_query_args = array(
'post_type' => 'page',
'post_parent' => $post->post_parent ,
'orderby' => 'menu_order'
);
else
$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() ) :
?>
<ul class="child_page_row">
<?php
while ( $child_pages->have_posts() ) : $child_pages->the_post();
?>
<li>
<a href="<?php the_permalink(); ?>">
<?php if(has_post_thumbnail()): ?>
<div class="child_page_thumb">
<?php the_post_thumbnail(array(240, 240)); ?>
</div>
<?php endif; ?>
<div class="child_page_name">
<?php the_title(); ?>
</div>
</a>
</li>
<?php
endwhile;
?>
</ul>
<?php
endif;
wp_reset_postdata();
}
add_shortcode('wpb_childpages', 'wpb_list_child_pages');
- 2 回答
- 0 關(guān)注
- 142 瀏覽
添加回答
舉報(bào)