WordPress.org

Ready to get started?Download WordPress

Forums

post_thumbnail in post? (15 posts)

  1. ttmt
    Member
    Posted 2 years ago #

    Hi all

    I'm still new to WP and I'm having problems displaying the featured image of posts.

    I have added theme support for post thumbnails in functions.php

    <?php
      add_theme_support('post-thumbnails');
      set_post_thumbnail_size( 50, 50, true );
    ?>

    I have added images as the featured image to posts.

    I have home.php as the Template page for a home page where I would like to display the post_thumbnail but the thumbnails don't display and the else echos 'no thumbs' is output.

    Is there anything obvious from the page why this isn't working or something else I need to do.

    Thanks in advance for any help.

    [Code moderated as per the Forum Rules. Please use the pastebin]

  2. Digital Raindrops
    Member
    Posted 2 years ago #

    Why is the closing after the content?

    HTH

    David

  3. ttmt
    Member
    Posted 2 years ago #

    sorry I didn't know about the forum number of lines of code rule
    here is the code

    http://pastebin.com/bQVcV33V

    Digital Raindrops - I don't undertand, why is what closing after the content?

  4. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    David is referring to the closing tag </a> for the link after 'the_content()' - having the link wrap the whole content is quite a stretch and can lead to problems and invalid code.

    there is no obvious reason in your code why a 'featured image' whould not get shown in the loop.

    are you sure you have a 'featured image' assigned to the post(s)?

    http://codex.wordpress.org/Post_Thumbnails

  5. ttmt
    Member
    Posted 2 years ago #

  6. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    just double checking:
    do you have a 'featured image' assigned to the post(s) in the dashboard - posts - edit post page, as in the attached screenshot?
    http://imageshack.us/photo/my-images/690/featuredimagedashboard.jpg/

    also, review http://codex.wordpress.org/Post_Thumbnails

    whatever images are within the post content does not matter.

  7. ttmt
    Member
    Posted 2 years ago #

    Yes I have a 'featured image' assigned to the post(s) in the dashboard.

    http://www.ttmt.org.uk/img.png

    I have read http://codex.wordpress.org/Post_Thumbnails but I can't see anything there that I haven't done.

    I think it might be time to give up.

  8. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    what happens if you remove the conditional code:

    change this section:

    <?php
                if ( has_post_thumbnail() ) {
                  the_post_thumbnail();
                }else{
                  echo 'no thumbs';
                }
                ?>

    to:

    <?php  the_post_thumbnail(); ?>

    - occasionally, a plugin interferes with some code;

    try to deactivate all plugins to see if that solves the problem; then re-activate one at a time to find the problem one.

  9. ttmt
    Member
    Posted 2 years ago #

    Removing the conditional and using

    <?php the_post_thumbnail(); ?>

    doesn't do anything. I was using the conditional statement to try and debug the problem.

    I'm only using NextGen gallery at the moment, I turned that off but still no luck.

  10. Digital Raindrops
    Member
    Posted 2 years ago #

    Hi,
    I have tested this, it is a Page template" so only can be used on a page:
    Copied your code from pastebin
    Created a file and saved it in a themes folder
    Run WordPress, went to a page,
    Set the featured image, and the template page as "Home" saved and viewed the page.

    The image shows just fine, so you code is fine, you say the theme has thumbnail support in the functions.php file?

    add_theme_support( 'post-thumbnails' );

    HTH

    David

  11. ttmt
    Member
    Posted 2 years ago #

    David thanks for your time looking into this.

    I think I might have this wrong, I'll explain what I was trying to do.

    I was hoping to create a simple photography gallery. I have a post for each
    section of the gallery. I have three posts with the titles Portrait, Fashion and Travel. Each of these posts have a featured image attached and a NextGen Gallery in the post with all the image for the section.

    I have a Page in WP with a title of Home(this is the first/index page). This page has home.php set as it's template.

    http://pastebin.com/MabrprQp

    So I simply wanted this home page to display each of the posts(Portrait,Fashion,Travel) featured images.

    ==

    If I add a featured image to the Home page in WP that is displayed. I think the code is working, but not to do what I wanted.

    Is it possible to display the featured image of each post on the home page?

    I really would appreciate any hep with this.

  12. todayheads
    Member
    Posted 2 years ago #

    i advice you to back up your site because some times it gives an error and ur site stops working backup it before doing anything

  13. ttmt
    Member
    Posted 2 years ago #

    todayheads - what site are you talking about?

    I haven't posted any sites here.

  14. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    thanks for explaining your setup.

    you need to add a query before the <?php if (have_posts()) : line to get the page template to show your choice of posts;

    example (to show 5 posts of all categories):

    <?php query_posts('cat=0&posts_per_page=5&paged='.get_query_var('paged')); ?>

    and after the <?php endif; ?> line, add:

    <?php wp_reset_query(); ?>

    http://codex.wordpress.org/Function_Reference/query_posts
    http://codex.wordpress.org/Function_Reference/wp_reset_query

  15. ttmt
    Member
    Posted 2 years ago #

    Thanks alchymyth, got it working now.

    I thought query_post was when I wanted to alter the default post that just outputs the posts

    The Codex even says

    For example, on the homepage, you would normally see the latest 10 posts. If you want to show only 5 posts (and don't care about pagination), you can use query_posts() like so:

    I see thats just the way it is but is there a reason I need the query and the post aren't just output?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.