3

我需要显示所有页面的特色图片,而不是帖子。我有这个代码:

<?php
if ((is_singular() || is_home()) && current_theme_supports('post-thumbnails')) : echo get_the_post_thumbnail( '12', 'full' ); ?>
<img src="<?php header_image(); ?>" class="header-img" alt="" />
<?php endif;?>

但这仅显示一张特色图片。

太感谢了!

4

1 回答 1

3

您可以简单地使用 WP_Query 来获得它,

$loop = new WP_Query( array( 'post_type' => 'page', 'meta_key' => '_thumbnail_id' ) );

或者,如果您想按照自己的方式进行操作,则需要先获取所有页面,然后循环遍历以获取其特征图像,

$args = array(
    'post_type' => 'page',
    'post_status' => 'publish'
); 
$pages = get_pages($args); 
foreach($pages as $page) {
        echo get_the_post_thumbnail( $page->ID, 'full' );
}
于 2013-05-15T16:45:23.303 回答