ThemeShaper Forums » Thematic

[closed]

Post thumbnail and featured image help!

(8 posts)
  • Started 3 years ago by krackpot
  • Latest reply from Ingvi
  • This topic is resolved
  1. krackpot
    Member

    I have been trying to find some sort of guide or tutorial for the post thumbnail feature that was implemented in 2.9. I know very little php or programming and the documentation seems incomplete or the forum posts seem very vague.

    I'm using the latest Development release at http://developing.thematic4you.com/thematic-development-release/ and I'm creating my own child theme.

    A note which may help others:
    - Post Thumbnail image that you see in some tutorials around the web is really called "Featured Image" when you try to add a new post (bottom right hand side). They've renamed this from 2.9 -> 3.0, and I wish they just left it alone to avoid confusion!

    So I still don't know how to hook this get_the_post_thumbnail() into the post.

    All I want to do is have the post thumbnail appear before the first word of the post (like the body of the post). Like this: After the title, after the meta, POST THUMBNAIL, the text of the post, the footer meta.

    I just want to put this "Bulletproof" check for backwards compatability too:
    if ( (function_exists('has_post_thumbnail')) && (has_post_thumbnail()) ) {
    the_post_thumbnail();
    } else {
    $postimage = get_post_meta($post->ID, 'post-image', true);
    if ($postimage) {
    echo '<img src="'.$postimage.'" alt="" />';
    }
    }

    I found this on the forums:
    add_theme_support( 'post-thumbnails' );

    function my_post_title($title) {
    return get_the_post_thumbnail(NULL, 'thumbnail') . $title;
    }
    add_filter('thematic_postheader_posttitle', 'my_post_title');

    Which I changed to:
    add_filter('thematic_postheader_postmeta', 'my_post_title');

    Which is the exact position where I want it, but in the markup, it's contained in a different <div>. I tried hooking or filtering or add action'ing to the thematic_post(), but that wipes the body of the post out and just displays the image. :(

    Frustrating! I've spent 3+ hours on this problem. I still don't have a good solution. Please help!

    Posted 3 years ago #
  2. Thompson
    Member

    Let's try to figure this out together. Here is what I have to add thumbnails to excerpts. If you're trying to add to full posts, I think you just need the first one "// Add Thumbnail Support for Theme (introduced in 2.9)" and the third "// Add post thumbnail to post excerpt" (but you'll have to change the last line from 'get_the_excerpt' to something else, probably 'get_the_post' (but someone else would know better than I on that.). Hope that gets your closer!

    // Add Thumbnail Support for Theme (introduced in 2.9)
    if ( function_exists( 'add_theme_support' ) ) {
    add_theme_support( 'post-thumbnails' );
    set_post_thumbnail_size(100, 100, true);
    }
    // Change default content display on home page to excerpt
    function childtheme_content($content) {
    if (is_home() || is_front_page()) {
    $content= 'excerpt';}
    return $content;
    }
    add_filter('thematic_content', 'childtheme_content');
    // Add post thumbnail to post excerpt
    function add_post_thumb($title) {
    return get_the_post_thumbnail(NULL, 'thumbnail') . $title;
    }
    add_filter('get_the_excerpt', 'add_post_thumb');
    // for above--use thematic_postheader_posttitle OR get_the_excerpt
    // Add read more link to excerpts and wrap excerpt in p tag
    function all_excerpts_get_more_link($post_excerpt) {
    return '<p>' . $post_excerpt . ' ... ID) . '">'.'continue &raquo' . '</p>';
    }
    add_filter('wp_trim_excerpt', 'all_excerpts_get_more_link');

    Does anyone know how to get post titles to appear *next* to the thumbnail, not above or below?
    I think it's a matter of using something different than 'get_the_excerpt' in the third set, BUT even 'thematic_postheader_posttitle' with a float left on the image doesn't work. The image is on the line above the title.

    Posted 3 years ago #
  3. Thompson
    Member

    I found a sol't to my problem following the tags on your post! Even though searching earlier didn't work.

    Turns out thematic_postheader_posttitle works to get thumbnails to the left of the post excerpt. But Thematic's parent CSS uses clear all on the header tags. Adding clear:none to my child style.css worked great to get thumbnails next to the excerpt, not on top or below.

    h1,h2,h3,h4,h5,h6 {
    clear:none;
    }

    Posted 3 years ago #
  4. krackpot
    Member

    Great news!

    I used your function and got the result I wanted:
    function add_post_thumb($title) {
    return get_the_post_thumbnail(NULL, 'thumbnail') . $title;
    }
    add_filter('get_the_excerpt', 'add_post_thumb');
    add_filter('the_content', 'add_post_thumb');

    "the_content" Allows me to place the post-thumbnail right before the first word in the post!

    We did it!

    Posted 3 years ago #
  5. I've been messing around with post thumbnail stuff all weekend...

    While WP3.0's thumbnail support is...passable, I'm finding that using Justin Tadlock's get_the_image plugin provides much more flexibility. It'll automatically scan posts for images, so you don't have to use custom fields, which is huge in the usability department. Coupling this with timthumb for correct image resizing and cropping made for a VERY flexible solution to adding images to post loops.

    Here's a snippet I found on another thematic user's site that I use in a custom loop to display post images, showing how to use the two plugins together. It wouldn't take much to turn this into a "the_content" filter so you don't have to use it in a page-template custom loop.

    <?php if ( function_exists( 'get_the_image' ) )
    		$get_the_image_as_array = get_the_image( array( 'image_scan' => true, 'format' => 'array','default_size' => 'medium' ) ); ?>
    						<a href="<?php echo $get_the_image_as_array[link]; ?>"><img src="<?php bloginfo('stylesheet_directory') ?>/includes/plugins/timthumb.php?w=268&h=160&zc=1&src=<?php echo $get_the_image_as_array[url]; ?> " alt="<?php echo $get_the_image_as_array[alt]; ?>"/></a>
    Posted 3 years ago #
  6. Thompson
    Member

    Tarpontech, You should post a brief how-to on that. I think it'd be SUPER useful for MANY people here! (Google has very little on the trio of WP + Get The Image + TimThumb)

    I've also created a custom index loop and use the Get The Image plugin. Now I'm deciding b/twn TimThumb and Smart Image Resizer, which I hear may be better-it even sharpens images automatically!

    1) Did you have to install the GD library for TimThumb?
    2) Have you seen Smarter Image Resizer? http://shiftingpixel.com/2008/03/03/smart-image-resizer/

    Posted 3 years ago #
  7. I created a bit of a tutorial, albeit not a straight-forward cut-n-paste one, on my site's blog over at tarpontech.net, focused mostly on getting this kind of setup to work on WPmu sites. I stuck in some good links, so it should help nudge folks in the right direction.

    I only found one article regarding the trio, but it was enough. You really just need to figure out how to get them working separately, then gluing them together was much easier. There's ton's of articles out there on timthumb, and Justin Tadlocks documentation on Get-The-Image was more than enough for a noob like me to get it running, its a very "point-and-shoot" plugin.

    1. I don't know what the GD library is...so i suppose i didn't use it...must google it.
    2. I went with Timthumb only because the majority of themes I see use it, i'm reading about smart-image-resizer now...but doubtful i'll switch...if it ain't broke...

    Posted 3 years ago #
  8. A note which may help others:
    - Post Thumbnail image that you see in some tutorials around the web is really called "Featured Image" when you try to add a new post (bottom right hand side). They've renamed this from 2.9 -> 3.0, and I wish they just left it alone to avoid confusion!

    @krackpot Thank you for these infos, I have been going crazy over this all day, grr:D

    Posted 2 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.