WordPress.org

Ready to get started?Download WordPress

Forums

Add a featured image to a PAGE rather than post (8 posts)

  1. ch8rt
    Member
    Posted 4 years ago #

    How do I go about using featured images with pages rather than posts? Is it even possible?

    I've already been using them with posts, but can't figure out how to use them on pages as well.

  2. vtxyzzy
    Member
    Posted 4 years ago #

    Take a look through all the 'images' plugins in the WP repository. Many of them allow you to put images wherever you wish.

  3. Milan Golubović
    Member
    Posted 3 years ago #

    Got exactly same problem.
    WP docs say that thumbnails can be enabled for post and/or for pages(!):

    http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails

    But only there. On all other places only posts are mentioned ?!?

    Also, when I enable thumbnails for pages I can select one for every page.
    It works well in admin part. But in template I can't picture I uploaded with the_post_thumbnail() ?!?
    Also for that function docs says that it must be inside loop?!? Why if I'm using thumbnail attached to page, not to post.

    I'm new to WP, but constantly I'm finding some illogical docs, examples...

    Please, help, advice.

  4. Rev. Voodoo
    Volunteer Moderator
    Posted 3 years ago #

    pages and posts use loops....

    add theme support for post thumbnail makes it work so you can upload the thumbnail

    but each template you want thumbnails displayed on must call the_post_thumbnail to display the images

    page.php for pages
    index.php for index/blog list view
    single.php for single post view
    etc...

  5. Milan Golubović
    Member
    Posted 3 years ago #

    Thanks RVoodoo for your reply,

    Yes, I added theme support and I can upload thumbnail for every page. That works fine.

    But "the_post_thumbnail()" is not outputting anything?
    I'm just putting that function call in header template (because every page have some picture) at place where I want page photo to appears - is that enough?
    Do I have to put it inside of some kind of loop? I mean I'm showing one page in a time and I got one thumbnail for a page, so I don't understand what can I loop here?

  6. supervee
    Member
    Posted 3 years ago #

    the_post_thumbnail() has to go inside the loop of the page you want it to appear, not in header.php (because it is not a post)

  7. Rev. Voodoo
    Volunteer Moderator
    Posted 3 years ago #

    the loop still exists in page.php

    It starts at if have posts while have posts line,

    and ends at the endwhile endif

    so your the_post_thumbnail code goes in between there

    If you want to display thumbnails in the header, you will need to figure out a way to call them.... probably using a little mini loop
    http://codex.wordpress.org/The_Loop

  8. Primoz Frelih
    Member
    Posted 3 years ago #

    Hi, find and add this to your "add_theme_support" function in functions.php:

    add_theme_support( 'post-thumbnails', array( 'post', 'page' ) );

    It's also useful for the custom type posts, just add them to the array.

Topic Closed

This topic has been closed to new replies.

About this Topic