Forums

Automatically Thumbnail Old and Current Posts via Custom Field? (3 posts)

  1. hellove
    Member
    Posted 7 months ago #

    Hello,

    I have been using a theme that didn't support thumbnails on the home pages for over three years. I now have a massive amount of content without thumbnail posts.

    I want to switch to a theme that does support thumbnails. Is there a way to automatically generate thumbnails for all of my wordpress posts based on the first image in any given post to accomplish this? I really like some of the modern looks of these types of themes but it would be impossible to go back and custom field thumbnails one-by-one.

    If anyone knows of a solution for this, I would really appreciate it?

    Thank you!

  2. hellove
    Member
    Posted 7 months ago #

    bump, anyone?

  3. esmi
    Theme Diva & Forum Moderator
    Posted 7 months ago #

    Try:

    <?php
    $args = array( 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => $post->ID );
    $attachments = get_posts($args);
    if ($attachments) {
    	$thumb = $attachments[0];
    	echo wp_get_attachment_image( $thumb->ID, 'thumbnail' );
    }
    ?>

    http://codex.wordpress.org/Function_Reference/get_posts
    http://codex.wordpress.org/Function_Reference/wp_get_attachment_image

Reply

You must log in to post.

About this Topic