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.

another question about image.

Can I add/attach images to post without adding it to post? The reason behind this is so that I can manipulate it whatever I want using API.

share|improve this question
    
I think your question is a bit unclear. When you write add/attach do you mean you want to insert it into the post? –  hakre Nov 4 '10 at 2:35
    
I want to associate several photos to post but I don't want to add it to post (eg, not shown in post but it's linked to that post). Is that clear enough? –  ariefbayu Nov 4 '10 at 2:38
add comment

3 Answers 3

up vote 4 down vote accepted

There is a Plugin called Attachments http://wordpress.org/extend/plugins/attachments/ Maybe this is something you looking for.

share|improve this answer
    
this is what I need. Thanks –  ariefbayu Nov 4 '10 at 8:31
    
It seems this does not save attachments in the same way the "core" WordPress systems saves attachments? Very similar, but not the same? –  Jan Fabry Nov 4 '10 at 15:50
    
@Jan: No but it sounds exactly what silent asked for. Its a nice way to attach files to a post from the complete media library. I know that the folks from wordpress-deutschland got a plugin that let you attach media files to more then 1 post. –  Horttcore Nov 5 '10 at 7:43
add comment

Yes, you can.

If you upload the image using the media uploader on a post's edit screen, or use update_post() to set the post_parent field of the attachment to the ID of the post you want to attach it to, it is associated with that post, whether or not it is actually inserted into the content of that post.

You can retrieve all images attached to a specific post by calling get_children() (see the codex for examples).

share|improve this answer
add comment

Yes, its definitely possible: I do this in one of my themes.

You simply add your images to the post as if you were going to insert it into the post, but then just click save all changes, and do not actually click the button "Insert Into Post".

Then, you can access that post's gallery images using something like:

$images = get_gallery_images();

where I've defined that function in functions.php:

// get all of the images attached to the current post
    function get_gallery_images() {
        global $post;
        $photos = get_children( array('post_parent' => $post->ID, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID') );
        $galleryimages = array();
        if ($photos) {
            foreach ($photos as $photo) {
                // get the correct image html for the selected size
                $galleryimages[] = wp_get_attachment_url($photo->ID);
            }
        }
        return $galleryimages;
    }

And then do whatever you'd like to those images in your template files. (In my case, I loop through the images and put them in a jQuery slider).

There are also plugins that you could use, but its always best to minimise plugins if you can help it.

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.