I have a photographer client who I am building a website for. The client does a lot of wedding photography and the likes, and what he would like to be able to do is display the client a gallery of their photographs and allow them to order the ones they like, giving them the option of size, format, etc.
In my head, I thought the best way of doing this would be to somehow intercept the [gallery] output, so that for each image that is returned, I add the product options fields for Foxycart to use.
How would I go about doing this - or is there perhaps a better way of doing this that I haven't thought of?
Dan Fraticiu answers:
You could mirror the [gallery] short code. And by mirror I mean simply copy it, you can find it [[LINK href="http://phpxref.ftwr.co.uk/wordpress/nav.html?wp-includes/media.php.source.html#l628"]]here[[/LINK]] or in <strong>wp-includes/media.php</strong> function name gallery_shortcode().
You paste that function in your functions.php file of your theme, change it's name with something like foxy_gallery_shortcode, then the shortcode like this:
Now you should be able to add you custom code in the foreach that builds the gallery.
Dan Davies comments:
This seemed like a viable solution, but unfortunately I'm getting the following error upon coping the function into my functions.php file and renaming it to foxy_gallery:
Warning: Cannot modify header information - headers already sent by (output started at .../functions.php:114) in .../wp-includes/pluggable.php on line 865
Utkarsh Kukreti answers:
You can fetch a list of the attachments using something like
$attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
You can get the attachment link using [[LINK href="http://codex.wordpress.org/Template_Tags/wp_get_attachment_link"]]wp_get_attachment_link[[/LINK]]
Some more useful functions are available at [[LINK href="http://svn.automattic.com/wordpress/trunk/wp-includes/media.php"]]wp-includes/media.php[[/LINK]]
Ben Huson answers:
Have you thought about using any of the WordPress ecommerce plugins?
I know WP e-Commerce can handle downloadable products like MP3 and probably images.
Dan Davies comments:
As each of the purchasing options are going to be the same for every image, it'd be an unnecessarily lengthy process to use an eCommerce system and manually add each image as a product. FoxyCart is an ideal solution, I just need a way of intercepting the code generated by the [gallery] shortcode so that I can add the fields after each image.