0

I'm creating my own theme, my little practice. I added the_post_thumbnail in index.php page. All latest post's featured images are showing on home page except Page featured image.

While I added the_post_thumbnail in index.php, I don't understand why the page featured image is not showing up on the home page.

Any suggestions? edited post i think my code not supported page featured image. here's my code

 <?php while(have_posts()) : the_post() ?>
                <div class="post">
                    <h2 class="title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                    <div class="entry"> 
               <a href="<?php the_permalink(); ?>" class="image image-full">
                            <?php  the_post_thumbnail('full');  ?>
               </a>

                    </div>
                </div>
                <div style="clear: both;">&nbsp;</div>
                         <?php endwhile; ?>
2
  • the_post_thumbnail displays the featured image for a given single post. What do you define as the "page featured image" Commented Dec 7, 2014 at 13:40
  • the_post_thumbnail can be used for page featured image too, but you will need to call it outside of the loop, (this also apply to the_title(), the_description() etc..) In your code you call it in the loop and it will retrieve posts images, call it before if( have_posts) {
    – knif3r
    Commented Jul 10, 2016 at 12:45

1 Answer 1

0

I think you'd need to get the actual page object and find the ID from there. Then, you can pass that ID to the_post_thumbnail(), otherwise I think the ID of a post in the loop will be used, not the actual home page. Try this $page_object = get_queried_object(); to get info about your home page.

9
  • Dear, Dan and Peter goosen, see it and now tell is this code support page featured image code??? Commented Dec 8, 2014 at 13:33
  • Where exactly are you adding a featured image in the admin area?
    – Dan
    Commented Dec 8, 2014 at 13:43
  • yeah. I add featured image via "set featured image" option. it works fine on posts... Commented Dec 9, 2014 at 6:11
  • I think you need to try the code I suggested. The featured image of the blog page will not be used in the loop, you have to get this using the ID of the page you're on, which you can find using get_queried_object()
    – Dan
    Commented Dec 9, 2014 at 9:52
  • Mr.Dan can u edit it in my code or give hint of using this object?? I'm not understanding it. please if you try one more time... Commented Dec 9, 2014 at 19:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.