• cscott5288

    (@cscott5288)


    OK, so I am trying to take advantage of the new post thumbnail feature for wordpress 9. I am followed the instructions here:

    https://markjaquith.wordpress.com/2009/12/23/new-in-wordpress-2-9-post-thumbnail-images/

    But am unable to see the thumbnails.

    Here is my functions (within php tags of course):
    add_theme_support( ‘post-thumbnails’, array( ‘post’ ) ); // Add it for posts
    add_theme_support( ‘post-thumbnails’, array( ‘page’ ) ); // Add it for pages

    set_post_thumbnail_size( 50, 50 ); // 50 pixels wide by 50 pixels tall, box resize mode

    And here is a link to my index.php template.

    As you can see, I have if has_post_thumbnails within the loop and <?php the_post_thumbnail(); ?> within a divider, after the excerpt. The page I am testing it on is: https://www.hospiceinform.net.

    Thanks, I would appreciate any help. I just can’t figure out why the thumbnails are not displaying.

Viewing 15 replies - 1 through 15 (of 22 total)
  • esmi

    (@esmi)

    Instead of:

    <?php
    if ( has_post_thumbnail() ) {
    	// the current post has a thumbnail
    } else {
    	// the current post lacks a thumbnail
    }
    ?>

    try:

    <?php if( function_exists( 'add_theme_support' ) ) the_post_thumbnail(); ?>

    Thread Starter cscott5288

    (@cscott5288)

    Hmm, still no change.

    esmi

    (@esmi)

    Got it! Change:

    add_theme_support( 'post-thumbnails', array( 'post' ) ); // Add it for posts
    add_theme_support( 'post-thumbnails', array( 'page' ) ); // Add it for pages

    to:

    add_theme_support( 'post-thumbnails' ); // Add it for posts & pages

    Thread Starter cscott5288

    (@cscott5288)

    Thanks for all the help but, unfortunately, there is still no change.

    Thread Starter cscott5288

    (@cscott5288)

    Could it be that I am not putting the code in index.php in the right places?

    Here is index.php as it is now:

    https://wordpress.pastebin.com/Dm5KC9Nq

    Thanks for all the help

    esmi

    (@esmi)

    It’s in 2 places right now, so get rid of the <?php if( function_exists( 'add_theme_support' ) ) the_post_thumbnail(); ?> line first. Other than that, I don’t see why it doesn’t work. I’ve used almost exactly the same code in multiple templates/themes.

    <div class="postcontent">
    <?php if( function_exists( 'add_theme_support' ) ) the_post_thumbnail(); ?>
    <?php the_excerpt();?>
    </div>
    Thread Starter cscott5288

    (@cscott5288)

    Oh, so <?php the_post_thumbnail(); ?> is interchangeable with <?php if( function_exists( ‘add_theme_support’ ) ) the_post_thumbnail(); ?>
    ?

    Odd that it is not working.

    hmmm…this thread has gotten me confused! I’m just gonna post up the code I use in case it helps ok?

    functions.php

    // THIS IS THUMBNAIL SUPPORT
    if ( function_exists( 'add_theme_support' ) ) { // Added in 2.9
    	add_theme_support( 'post-thumbnails' );
    	set_post_thumbnail_size( 50, 50, true ); // Normal post thumbnails
    	add_image_size( 'single-post-thumbnail', 400, 9999 ); // Permalink thumbnail size
             add_image_size( 'title-image', 50, 30 ); // Title mini photo
    }
    //THIS TURNS THUMBNAIL INTO LINK TO POST
    add_filter( 'post_thumbnail_html', 'my_post_image_html', 10, 3 );
    
    function my_post_image_html( $html, $post_id, $post_image_id ) {
    
    	$html = '<a href="' . get_permalink( $post_id ) . '" title="' . esc_attr( get_post_field( 'post_title', $post_id ) ) . '">' . $html . '</a>';
    
    	return $html;
    }

    Then in my index.php I use:
    <?php the_post_thumbnail('title-image', array('class' => 'titleImage', 'alt' => 'Title Icon')); ?>
    to call up my tiny pic….its just an itty bitty icon

    Then in index I also use:
    <?php the_post_thumbnail(array( 75,75 ), array('class' => 'postImage', 'alt' => 'Post Thumbnail')); ?>
    Which is a larger square thumbnail size

    And in single.php I use:
    <?php the_post_thumbnail('single-post-thumbnail', array('class' => 'pageImage', 'alt' => 'Full Page Image')); ?>
    Which gets me a big ole (400px wide) picture

    Hmm….I was trying to help….but I think I’ve made it clear..as mud. Ignore me if this just confuses further

    Thread Starter cscott5288

    (@cscott5288)

    Wow wow wow. Wait a sec. I had <?php if( function_exists( ‘add_theme_support’ ) ) the_post_thumbnail(); ?> in my page template. Am i supposed to have that in functions.php?

    nope…. thats a fail safe….the if function_exists bit keeps your theme safe for older WP versions. Its not technically required if you are using the newest WP, and never plan to release your theme to public.

    But it’s really only needed once, I beluieve. I personally keep it on the functions.php side

    Thread Starter cscott5288

    (@cscott5288)

    OK, I posted Voodoo’s exact code. Still nothing. Here is the main index (code is just before excerpt):
    https://pastebin.com/RkGpktWm

    Here is functions.php (code is at the bottom):
    https://pastebin.com/1XbsZS31

    Hmm…the code looks good….so when you go to make a new post, there isn’t a little box over on the right side now which allows you to insert/upload your desired thumbnail for the post?

    Thread Starter cscott5288

    (@cscott5288)

    OH shoot there is! I thought this code automatically grabbed the first picture in a post and displayed a thumbnail of it lol.

    How do I do that?

    Thanks so much RVoodoo and esmi

    Thread Starter cscott5288

    (@cscott5288)

    But even with this code, I can choose a thumbnail while editing a post but the thumbnail won’t show up in my index.php despite having placed: <?php the_post_thumbnail(‘title-image’, array(‘class’ => ‘titleImage’, ‘alt’ => ‘Title Icon’)); ?>
    in index.php

    How do I do that?

    I’ve seen a few topics recently about that….I’m not sure exactly how to do it tho. You may want to try digging in to see if you can find one of those. Or maybe start a new thread now that you know what you are looking for a bit better.

    As for the image not showing up….I’m really not sure. I’ll peep your code again, but it works great on my site…..

Viewing 15 replies - 1 through 15 (of 22 total)
  • The topic ‘Trying to get post thumbnails working on my theme … err’ is closed to new replies.