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 am looking for a way to create a Photo Post type. Basically a post that is a title and a single image. Where I am getting stuck is the actual attaching an image to a post. I would like to have an image upload field in a metabox. I followed this guide. I am able to see the WP upload box and I upload an image from my machine and click "Insert into Post". Then I publish the post. I don't know if the image is actually attached to that post though. I see the post in the database as well as the image as an "attachment" post_type.

Is this a good direction to go in if all I want is a simple attach a single image to a post along with a title?

Also, is there any way to simplify the media upload lightbox just for a certain post type? (Making it so the user doesn't need to know to click "Insert into Post" instead of "Save All Changes"?

share|improve this question
    
why don't you use the feature image? –  andresmijares25 Dec 7 '11 at 4:33
    
Are you able to use the full sized image? Or turn resizing off? –  Brandon Dec 7 '11 at 4:40
    
you can use set the width to the same size of your content, and set an standard height, if the image is smaller it won't affect anything... I wrote it better below, also make sure your custom post type supports the thumbnail as Joshua said below... –  andresmijares25 Dec 7 '11 at 4:57
    
Ah, ok. I have it figured out. What about the media upload lightbox, any way to simplify it? (i.e. Change layout) To make it easier to set a featured image? Or at least change the language? –  Brandon Dec 7 '11 at 5:03
    
I guess you have to assign a specific class to the image in order to make the Lightbox work... then check the update in my answer... that is what I would do... –  andresmijares25 Dec 7 '11 at 5:07

2 Answers 2

In your functions.php... The size are relative... you can use your same size container and align the image to the left if it's the case...

 if ( function_exists( 'add_image_size' ) ) { 
   add_image_size( 'post-photos', 900, 800);
 }

Custom Post Template

 <?php if(has_post_thumbnail()): ?>
   <?php the_post_thumbnail('post-photos', array('class' => 'post-photos-image')); ?>
 <?php endif; ?>

If using lightbox and you need to assign the ligtbox class to the image:

In your post template into the loop

 <?php
    $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
 ?>
  <?php if($url !="") { ?>
      <img src="<?php echo $url; ?>" class="LIGHT-BOX CLASS">
  <?php } else {?>
               <!--Do not display image tag if there is none image attached-->
   <?php } ?> 
share|improve this answer
    
Oops, sorry. By lightbox I meant the media upload window that pops up when you click "Set Featured Image". i.imgur.com/f0E5W.png I want to be able to simply the layout so the user knows to click "Set Featured Image" if they want to insert into the post. –  Brandon Dec 7 '11 at 5:34

If you want just a title and an image I suggest you put this argument when registering the custom post type -> 'supports' => array( 'title', 'thumbnail' ),

share|improve this answer

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.