WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Displaying post_thumbnail for a Specific Page (10 posts)

  1. Demonhood
    Member
    Posted 4 years ago #

    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.

  2. vtxyzzy
    Member
    Posted 4 years ago #

    I think get_the_post_thumbnail will do what you want.

  3. Demonhood
    Member
    Posted 4 years ago #

    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.

  4. vtxyzzy
    Member
    Posted 4 years ago #

    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?

  5. Mark / t31os
    Moderator
    Posted 4 years ago #

    Feed the function the page's ID ...

    <?php echo get_post_thumbnail( 'page_id_goes_here' ); ?>
  6. Demonhood
    Member
    Posted 4 years ago #

    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?

  7. vtxyzzy
    Member
    Posted 4 years ago #

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

  8. Demonhood
    Member
    Posted 4 years ago #

    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. :)

  9. Demonhood
    Member
    Posted 4 years ago #

    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.

  10. vtxyzzy
    Member
    Posted 4 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic