WordPress.org

Ready to get started?Download WordPress

Forums

Use more than one Post Thumbnail in WP 2.9 (8 posts)

  1. adamhdv
    Member
    Posted 4 years ago #

    Wondering if anyone knows (or if it's even possible) to use more than one Post Thumbnail in WP 2.9.

    I have my functions.php set up as:

    <?php if ( function_exists( 'add_theme_support' ) ) { // Added in 2.9
    	add_theme_support( 'post-thumbnails' );
    	set_post_thumbnail_size( 100, 35, true ); // Normal post thumbnails
    	add_image_size( 'single-post-thumbnail', 400, 9999 ); // Permalink thumbnail size
    }?>

    And call my image (on my homepage) I set when writing a post as:
    <?php the_post_thumbnail(); ?>

    Is there a way to add more than one Post Thumbnail when writing a post and have it displayed?

    Thanks! :]

  2. I don't think so, but what are you trying to accomplish? There may be a better way around that.

  3. adamhdv
    Member
    Posted 4 years ago #

    I wanted to use this to place additional photos of a post on the homepage along side the main image being displayed for each post.

    Ultimately, I could do it with custom fields but I like the ease of the feature of the new Thumbnail option.

  4. That's probably going to be the best way about it, unless you make a plugin. Which is how Post Thumbnails started in the first place ;)

  5. vteixeira
    Member
    Posted 4 years ago #

    You don't need a plugin, you can use wp_get_attachment_image or wp_get_attachment_image_src to retrieve the post attached images.

  6. adamhdv
    Member
    Posted 4 years ago #

    @vteixeira: Woah, I didn't know wp had that built in. Do I need to include anything in functions.php to use that?

  7. adamhdv
    Member
    Posted 4 years ago #

    After looking into this a bit more...this is what I did. Not sure if it's right or wrong, but it seems to work.

    In functions.php:

    <?php $args = array(
    'post_type' => 'attachment',
    'post_mime_type' => 'image',
    'post_parent' => $post->ID
    );
    $images = get_posts( $args );
    foreach($images as $image):
    endforeach;
    ?>

    Inside the loop:
    <?php echo wp_get_attachment_image($images[0]->ID, 'thumbnail'); ?>

    Using [0],[1]...etc to set the number of images I wanted.

    Thoughts?

  8. adamhdv
    Member
    Posted 4 years ago #

    ^^above actually displays the same images for every single post instead of using images per each post. Anyway to fix that?

Topic Closed

This topic has been closed to new replies.

About this Topic