WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Post thumbnail fristrations (7 posts)

  1. manntis
    Member
    Posted 4 years ago #

    Sometimes WordPress takes the first image I add to an article and makes that into the post thumbnail. Other times it takes the second. Or whatever inage it feels like. And even if I remove the image from the article, IT KEEPS IT AS THE THUMBNAIL.

    Bloody hell this is frustrating. Why can't there be a "Use as thumbnail" checkbox in the image upload? And why the hell does it keep the thumbnail even if you remove the image because WordPress decided to arbitrarily use the 2nd one uploaded instead of the first, or vice versa? Some predictabiity in what WP is going to do would be friggin appreciated.

  2. tgiokdi
    Member
    Posted 4 years ago #

    Sounds like this is something that's theme related, because WP doesn't do any auto inserting of thumbnails. what kind of thumbnails are you talking about? The gallery shortcode ones, or ones that have been inserted via the media manager?

  3. manntis
    Member
    Posted 4 years ago #

    the thumbnails that are generated from images placed in articles, then used on the main page article summaries.

    I grab them using

    dp_attachment_image($post->ID, 'thumbnail', 'alt="' . $post->post_title . '"');

    which calls

    function dp_attachment_image($postid=0, $size='thumbnail', $attributes='') {
    	if ($postid<1) $postid = get_the_ID();
    	if ($images = get_children(array(
    		'post_parent' => $postid,
    		'post_type' => 'attachment',
    		'numberposts' => 1,
    		'post_mime_type' => 'image',)))
    		foreach($images as $image) {
    			$attachment=wp_get_attachment_image_src($image->ID, $size); ?>
    
    <img src="<?php echo $attachment[0]; ?>" <?php echo $attributes; ?> />
    <?php
    		}
    }
  4. manntis
    Member
    Posted 4 years ago #

    I found a workaround.

    if you add this code to your functions.php:

    if ( function_exists( 'add_theme_support' ) ) {
    	    add_theme_support( 'post-thumbnails' );
    	    set_post_thumbnail_size( 80, 80, true );
    	}

    it creates a menu in the right column of your admin panel for editing posts that lets you select which image to use as the thumbnail. Modify the 80 x 80 to whatever dimensions you prefer.

    *whew*

  5. manntis
    Member
    Posted 4 years ago #

    No, I spoke too soon. Adding that code gives you the *illusion* of being able to set which one you want as the thumbnail.

    WordPress still does whatever it bloody well wants, and it's usually the exact opposite of what you want it to do.

    Add two photos? Sometimes it'll use photo A as the article thumbnail, sometimes photo B. Remove them both and put them back in reverse order? It'll still choose the photo you DON'T want and make it the thumbnail

    It's like it reads your mind, then decides to screw with you.

  6. Daiv Mowbray
    Member
    Posted 4 years ago #

    Hey Manntis,
    your theme function dp_attachment_image fails to state which order to use.
    try adding an order by clause to your array

    'post_type' => 'attachment',
    		'numberposts' => 1,
    		'post_mime_type' => 'image',
    'order_by' => 'menu_order',
    'order' => 'ASC')

    HTH

  7. manntis
    Member
    Posted 4 years ago #

    that appears to have worked! many thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.