/** * Retrieves all Attachments for provided Post or Page * * @param int $post_id (optional) ID of target Post or Page, otherwise pulls from global $post * @return array $post_attachments * @author Jonathan Christopher * @author JR Tashjian */ function attachments_get_attachments($post_id = null) { global $post; if ($post_id == null) { $post_id = $post->ID; } // get all attachments $existing_attachments = get_post_meta(absint($post_id), '_attachments', false); // We can now proceed as normal, all legacy data should now be upgraded $post_attachments = array(); if (is_array($existing_attachments) && count($existing_attachments) > 0) { foreach ($existing_attachments as $attachment) { // decode and unserialize the data $data = unserialize(base64_decode($attachment)); array_push($post_attachments, array('id' => stripslashes($data['id']), 'name' => stripslashes(get_the_title($data['id'])), 'mime' => stripslashes(get_post_mime_type($data['id'])), 'title' => stripslashes($data['title']), 'caption' => stripslashes($data['caption']), 'filesize' => stripslashes(attachments_get_filesize_formatted(get_attached_file($data['id']))), 'location' => stripslashes(wp_get_attachment_url($data['id'])), 'order' => stripslashes($data['order']))); } // sort attachments if (count($post_attachments) > 1) { usort($post_attachments, "attachments_cmp"); } } return $post_attachments; }
} else { $nextMarkup = ''; } echo $prevMarkup . $nextMarkup; ?> <div id="artwork-wrap" class="container_24"> <?php $existing_attachments = get_post_meta($post->ID, '_attachments', false); $post_attachments = array(); $thumb_id = get_post_thumbnail_id($post->ID); if (is_array($existing_attachments) && count($existing_attachments) > 0) { foreach ($existing_attachments as $attachment) { // decode and unserialize the data $data = unserialize(base64_decode($attachment)); //$is_thumb = $thumb_id == $data['id']? true : false ; array_push($post_attachments, array('id' => stripslashes($data['id']), 'name' => stripslashes(get_the_title($data['id'])), 'mime' => stripslashes(get_post_mime_type($data['id'])), 'title' => stripslashes($data['title']), 'caption' => stripslashes($data['caption']), 'filesize' => stripslashes(attachments_get_filesize_formatted(get_attached_file($data['id']))), 'location' => stripslashes(wp_get_attachment_url($data['id'])), 'order' => stripslashes($data['order']))); } // sort attachments if (count($post_attachments) > 1) { usort($post_attachments, "attachments_cmp"); $artwork_display_class = 'grid_18 push_6'; $artwork_meta_display_class = $artwork_display_class; $single_image_size = MBUDM_IMAGESIZE_18; } else { $artwork_display_class = 'single-attachment no-grid'; $artwork_meta_display_class = ''; $single_image_size = MBUDM_IMAGESIZE_WIDE_18; } $default_active_image_id = $thumb_id ? $thumb_id : $post_attachments[0]['id']; $active_image_id = isset($wp_query->query_vars['mb_aid']) ? $wp_query->query_vars['mb_aid'] : $default_active_image_id; ?>