views:

37

answers:

1

I'm looking to find a WordPress plugin that ads an upload widget to my post editor to allow me to associate images with posts.

The end result is that I can add a bit of code to my theme's single.php file that allows me to load all of the images that reside in the folder matching the post id.

If no such plugin exists, I'm looking for some help on creating one.

Here's the way it would work..

Any images uploaded to a specific post, will go into a folder named after the post id. For example, if you are editing the post with id=420, the uploaded files will go into a folder named "420". There would also need to be some way to add or remove images from the folder without leaving the post editor (though FTP could be used for this as well).

To show post specific images, the single.php file checks to see if there is a folder under wp-content/uploads matching the post id. If it finds a match, it simply loads all the images it finds in the folder.

A: 

You can already attach images to a post without including them in the main content. You can do all of this in the main Edit Post window (the first icon next to "Upload/Insert" above the text editor. They are added with the post id as parent_id parameter, so the get_children function will give you all attached files.

This will store the images in the standard /wp-content/uploads/ folder, grouped by year and month (if you checked that option in the administration page). If you want to change the upload directory, you can use the upload_dir filter (slightly outdated parameter list) and return a different upload directory, for example with the post ID. The upload_dir filter is called from wp_upload_dir(), which is called by wp_handle_upload(), which is called by media_handle_upload(), which is called from the media-upload.php file.

If you want to extend this idea and check the upload dir for new files (uploaded via FTP for example), and attach these to the post, I suggest you look into the attachment functions.

Jan Fabry
Thanks Jan, but I've got the "Use year/month folders..." toggle turned off. Thus all images uploaded to a post get inserted to the root of the uploads folder (I don't want to change this). I just need to hack into that script so that the uploaded images are loaded into a folder named with the postid of the current post being edited and I'm golden. Do you think I can add a filter to my theme options to do that?
Scott B
@Scott: I updated my answer with info on the `upload_dir` filter, which might be your hook to change the destination dir.
Jan Fabry