Filter for just one type of attachment
-
Im having trouble migrating to the new version because Im now not sure how to filter the attachments for a specific file type/mime. Below is a working example from before the rewrite which filters for images. Can someone help and point me in the right direction?
Many thanks
// ======================================== // ! Returns attached images as a gallery // ======================================== function tr_get_attachments_image($post){ global $post; $content_attach = ''; $is_test = ""; if( function_exists( 'attachments_get_attachments' ) ){ $attachments = attachments_get_attachments(); $attachments_count = count( $attachments ); //see if there are any images if ( $attachments_count ){ for ($i=0; $i < $attachments_count; $i++) { $mime = strtok($attachments[$i]['mime'], "/"); if ( strstr($mime, 'image') ) { $is_test = true; break; } } // if so only ouput the images if ( $is_test == true ) { $content_attach = '[fancybox]<div class="attached_gallery">'; $content_attach .= '<div class="attachment-title">'; $content_attach .= '<h4 class="gallery">Image Gallery</h4>'; $content_attach .= '</div>'; $content_attach .= '<ul id="" class="thumbnails gallery">'; for( $i=0; $i<$attachments_count; $i++ ){ // if attachment is jpeg, png, gif images extension if($attachments[$i]['mime'] == 'image/jpeg' || $attachments[$i]['mime'] == 'image/png' || $attachments[$i]['mime'] == 'image/gif' ){ // get attachment data for full version and thumbnail version. $full_image = wp_get_attachment_image_src($attachments[$i]['id'], 'full'); $thumb_image = wp_get_attachment_image_src($attachments[$i]['id'], 'thumbnail'); $content_attach .= '<li class="gallery-item brick" >'; $content_attach.= '<a class="fancybox thumbnail" rel="gallery" title="'.$attachments[$i]['title'].'" href="'.$full_image[0].'" >'; $content_attach .= '<img class="attachment-thumbnail" alt="' . $attachments[$i]['title'] . '" title="' . $attachments[$i]['title'] . '" src="'.$thumb_image[0].'" width="'.$thumb_image[1].'" height="'.$thumb_image[2].'"/>'; $content_attach .= '</a>'; $content_attach .= '</li>'; } } $content_attach .= '</ul>'; $content_attach .= '</div>'; } echo apply_filters('the_content', $content_attach ); } //if ($is_test != true ) echo "<p>no gallery?</p>"; } }
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Filter for just one type of attachment’ is closed to new replies.