Support » Fixing WordPress » Displaying post_thumbnail for a Specific Page

  • Resolved Demonhood

    (@demonhood)


    Greetings.
    How would I go about crafting my loop if I wanted to display only the post_thumbnail for one specific page?

    Using the standard loop, it pulls the thumbnail from one of my posts.

    The basic concept here is that I’ve got a php widget on my main page, and I want it to display a featured player (sports site). And there is a featured player page. So, once that page is updated with a thumbnail image, the main page will be as well. Easy peasy. Well, once I figure out how to do it that is.
    Any help is appreciated.

Viewing 9 replies - 1 through 9 (of 9 total)
  • I think get_the_post_thumbnail will do what you want.

    Yes, that’s what I’m using. But all the examples say “put this in your loop” without explaining how I can query a specific page (or sets of pages) with that loop instead of posts.

    Please explain a little more. If you can provide a link to your site, that would help. What theme are you using?

    You say you have a php widget. Does this widget have its own loop to retrieve posts?

    You say there is a ‘featured player page’. Is this really a page, or a post? If it is a post, how is it identified as a featured player?

    Feed the function the page’s ID …

    <?php echo get_post_thumbnail( 'page_id_goes_here' ); ?>

    It’s a custom theme and it’s not quite ready for primetime, so no link for now.

    You say you have a php widget. Does this widget have its own loop to retrieve posts?

    That’s the issue right there. How should this loop look to retrieve pages (or just one page) instead of all posts?

    You say there is a ‘featured player page’. Is this really a page, or a post? If it is a post, how is it identified as a featured player?

    It really is a page. ‘Featured Player’ is just the name of the page. It’s currently my only page with a thumbnail image (and likely will remain so).

    I can feed the function the page’s ID, but my current loop seems to only go thru posts. And I have another variable in there, in a custom post_thumbnail size. So how would that be formatted?

    That’s the issue right there. How should this loop look to retrieve pages (or just one page) instead of all posts?

    See the Codex Query Posts – Section Page & Post Parameters

    <?php query_posts('page_id = 44'); ?>

    Got it. I was making it much more complicated than it actually was.
    Here’s the final code for my php widget, for those interested:

    <?php $posts=query_posts('page_id=15');
    if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    	<?php the_post_thumbnail( 'featured' ); ?>
    <?php endwhile; endif; ?>

    That’s using the custom post_thumbnail size I defined in my functions.php file. Thusly:

    add_image_size('featured', 300, 260, true);

    Perfect widget size. 🙂

    Although if someone could clue me in on how to make the post_thumbnail the background image of a div, that’d be mighty helpful. Otherwise, a css hacking I will go.

    Since this topic is marked ‘Resolved’, it will not get many readers. You might have better luck starting a new thread.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Displaying post_thumbnail for a Specific Page’ is closed to new replies.