I have a page with a slide show at the top and images pasted into a row in the content area.
I need to exclude images that were inserted into the message from the slide show.
I currently exclude "Best Image", but this limits me to one image that can be inserted into the message.
Here is my existing code:
$thumbnail = get_post_thumbnail_id(); $images = get_children( 'post_type=attachment&post_mime_type=image&order=asc&orderby=menu_order&post_parent='.$post->ID .'&exclude='.$thumbnail);
I used to use the image metadata description field to exclude images by typing "exclude". This is not as pleasant for the end user as we would like.
Any suggestions, plugins or code based!
Update: I updated the code, so now I get the URLs of images from post_content and check them for slideshow images.
$content = $post->post_content; $inlineImages = array(); preg_match( '/src="([^"]*)"/i', $content, $inlineImages ) ; $thumbnail = get_post_thumbnail_id($post->ID); $images = get_children( 'post_type=attachment&post_mime_type=image&order=asc&orderby=menu_order&post_parent='.$post->ID .'&exclude='.$thumbnail); if ($images) { echo '<div id="slideshow">'; foreach ( $images as $attachment_id => $attachment ) { $image = wp_get_attachment_image_src( $attachment_id,array(900,265)); if (!in_array($image[0],$inlineImages)) { echo '<img src="'.$image[0].'" width="'. $image[1] .'" height="'. $image[2].'">'; } } echo '</div>'; }
This solution is OK, although regex can be improved.
A more pleasant step is to add an array of images to a custom field field, which is updated after publication / publication or publication.
Any suggestions on how to do this?
source share