3
votes

I need to show the featured images of all the pages, not the posts. I have this code:

<?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;?>

But this only shows one featured image.

Thank you so much!

1
So obviously you passing post id 12 so it will bring the feature image of that post. What you expecting ?Rikesh
a loop of featured images in all pages, i know i passing id 12 but how can i get the loop?krathos
This might be a question that belongs on wordpress.stackexchange.comjontro

1 Answers

3
votes

You can simply use WP_Query to get that,

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

Or if you want to do by your way you need to fetch all pages first & than loop over it to get thier feature image,

$args = array(
    'post_type' => 'page',
    'post_status' => 'publish'
); 
$pages = get_pages($args); 
foreach($pages as $page) {
        echo get_the_post_thumbnail( $page->ID, 'full' );
}