2
votes

I have a wordpress website that uses a plugin to insert images from PhotoShelter pages and posts. If I want to insert the images directly into content then this is fine, however, I can't currently use it to set featured images.

The plugin basically allows you to browse all of the photos on PhotoShelter through the standard image upload screen, and then when you click "insert into post" it hot links to the image on PhotoShelter. It doesn't attach it to the post in any way and the image doesn't appear in the Media Library.

Is there a way to look for images in the_content(), strip it out (I don't want images to display in the content area) and save it into an array along with the post ID? That way I could then use it for blog thumbnails in the archive template and elsewhere within the loop in my page template. Or maybe there is a way to change the featured image feature to allow me to select images from PhotoShelter?

This is the plugin I'm using: http://wordpress.org/extend/plugins/photoshelter-official-plugin/

Open to any suggestions on how to achieve this.

Thanks in advance :)

1
What's the reason for PhotoShelter?SMacFadyen
The client specifically requested it as they already use it for secure galleries for clients.Kirsty Burgoine

1 Answers

1
votes

The code below if used in your loop will capture all images used in the content into an array and remove them from the content.

/* get the post_content */
$content = get_the_content();

/* makes an array of images and stores them in $matches */
preg_match("/<img[^>]+\>/i", $content, $matches, PREG_OFFSET_CAPTURE, 3);

/* removes all images from the content */
$content = preg_replace("/<img[^>]+\>/i", "", $content);

/* display the content as normal */
echo wpautop($content);

The problem with this is the array will be filled with entries of img tags and really you only want the src of the image. Getting the src is tricky, see this question.

Even if you did manage to get all this working well it's still a bit of a funky solution to your problem. Your users would not be able to upload other pictures to their content besides the featured image.

A better solution would involve making a custom meta box which looks like the 'featured image' meta box but when clicked loads up the PhotoShelter modal and then allows you to save the picked image as post meta.

What kind of images does it output into your content? are they normal image links or do they have get variables stuffed in them?