Created
April 11, 2012 22:06
-
-
Save stellarcowboy/2363077 to your computer and use it in GitHub Desktop.
WordPress Image Attachment Toolbox
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function get_string_between($string, $start, $end){ //required for parsing attachment URL's in attachment_image_retrieve | |
$string = " ".$string; | |
$ini = strpos($string,$start); | |
if ($ini == 0) return ""; | |
$ini += strlen($start); | |
$len = strpos($string,$end,$ini) - $ini; | |
return substr($string,$ini,$len); | |
} | |
function attachment_image_retrieve($size = 'thumbnail', $limit = '-1') { | |
// Example for template php: attachment_image_retrieve('full', 3); | |
if($images = get_children(array( | |
'post_parent' => get_the_ID(), | |
'post_type' => 'attachment', | |
'numberposts' => $limit, | |
'post_status' => null, | |
'post_mime_type' => 'image', | |
'orderby' => 'menu_order', | |
'order' => 'ASC', | |
))) { | |
foreach($images as $image) { | |
$attimg = wp_get_attachment_image($image->ID,$size); // pulls size from function call | |
//$atturl = wp_get_attachment_url($image->ID); | |
//$slidelinkID = get_the_ID($image->post_parent); | |
//$slidelinktitle = get_the_title($image->post_parent); | |
//$slidelink = get_post_meta($slidelinkID, 'slide_link', true); | |
//$atttitle = apply_filters('the_title',$image->post_title); //image title | |
//$attcaption = apply_filters('the_title',$image->post_excerpt); //image caption | |
//$attdesc = apply_filters('the_title',$image->post_content); //image desc | |
//$parsed = get_string_between($attimg, "src=\"", "\" class="); | |
// echo '<a href="'.get_permalink($post->ID).'" title="'.get_the_title().'">'.$attimg.'</a>'; //links to post | |
// echo '<li><a class="thumb" href="'.$parsed.'" title="'.$atttitle.'"></a>'; //links to attachment | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment