WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Posting featured images by page id (2 posts)

  1. AlyssaMc
    Member
    Posted 1 year ago #

    I am trying to display the featured images of certain pages of my website on my homepage, which I want to call by page id. I can figure out how to do this for my recent posts, etc., but I want to call the featured images from only a few of my pages (not posts).

    I've tried fiddling with the following for a while, but I can't seem to get it to work:

    <?php
    	$page_id = 144;
    	$my_page = get_page( $page_id );
    	if( $my_page )
    	foreach( $my_page as $my_post ) : setup_postdata( $my_post );
    		the_post_thumbnail('full');
    	endforeach;
    	wp_reset_query();
    ?>

    Any thoughts?

  2. AlyssaMc
    Member
    Posted 1 year ago #

    Nevermind, I got it. In case you're interested:

    $the_query = new WP_QUERY ( 'page_id=144' );
    while ( $the_query->have_posts() ) :
    $the_query->the_post();
    the_post_thumbnail('full');
    endwhile;
    wp_reset_postdata();

Topic Closed

This topic has been closed to new replies.

About this Topic