Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have 70 posts I would like to add a feature image for. I have loaded all of the feature images to the media library. Can I 'make it the feature image' from the media library, or do I have to go into every post to select 'set a feature image' and then get it from the media library?? Thankyou.

share|improve this question
add comment

1 Answer

Here is an option though I'm not sure it will work as your expecting.

It works like this:

You need to upload the images you'll be using so they are in the media library. Once the images have been uploaded, navigate to the media library and look for the link that says unattached.

Media Library Unattached Link

-

Find the image you want to use and click on the attach to post link as shown here:

Find Posts or Pages Pop-Up

Type the post name or a word in the post title and click search.

Once you've found the post you want to attach the image to click on the radio button and then the select button to attach it to the post:

The final step to attach image to post

Now you have attached the image to a specific post but you still need some code to make it show up in the post. In the code below I've used an additional loop to display the first image attached in a post (this is why I said I'm not sure if it will work for you, if it doesn't work, there are a few things you can change).

Here is an example I used in an old theme I had laying around. The first loop displays the post text and the second displays the image you attached earlier:

<?php get_header(); ?>
  <!-- The Loop to display your post text: -->
  <?php if (have_posts()) : while ( have_posts() ) : the_post(); ?>
    <div class="singlepost" id="post-<?php the_ID(); ?>">
    <h2><?php the_title(); ?></h2>
      <div class="entry">
        <?php the_content(); ?>
      </div>
    </div>
  <?php endwhile; ?>
    <!-- Reset query so we can include the attached image in a second loop. -->
    <?php wp_reset_query(); ?>
      <ul class="custom-attachment">
        <?php if ( have_posts() ) : while ( have_posts() ) : the_post();
          $args = array(
            'post_type' => 'attachment',
            'numberposts' => -1,
            'post_status' => null,
            'post_parent' => $post->ID
            );
          $attachments = get_posts( $args );
          if ( $attachments ) {
            foreach ( $attachments as $attachment ) {
              echo '<li>';

            # To Link to large medium or small (thumbnail) 
            # uncomment the appropriate line below to display that size image: 

              echo wp_get_attachment_image( $attachment->ID, 'full', false );              
              // echo wp_get_attachment_image( $attachment->ID, 'medium', false );
              // echo wp_get_attachment_image( $attachment->ID, 'thumbnail', false  );
              echo '</li>';
              }
            }
          endwhile; endif;
          ?>
      </ul>
    <?php endif; ?>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.