Skip to content

Instantly share code, notes, and snippets.

@ms-studio
Created August 25, 2012 12:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ms-studio/3464907 to your computer and use it in GitHub Desktop.
Save ms-studio/3464907 to your computer and use it in GitHub Desktop.
WordPress image toolbox
// Image Toolbox
// ******************************
// based on http://digwp.com/2009/08/awesome-image-attachment-recipes-for-wordpress/
function image_toolbox($size = 'thumbnail', $howmany = -1, $link = 'no', $list = 'no') {
if ( $images = get_children ( array (
'post_parent' => get_the_ID(),
'post_type' => 'attachment',
'numberposts' => $howmany , // -1 = show all
'post_status' => null,
'post_mime_type' => 'image',
'orderby' => 'menu_order',
'order' => 'ASC',
// 'linked' => $link, // link = create link
))) {
foreach ( $images as $image ) {
$attimg = wp_get_attachment_image($image->ID,$size);
$atturl = wp_get_attachment_url($image->ID);
$attlink = get_attachment_link($image->ID);
//$postlink = get_permalink($image->post_parent);
//$atttitle = apply_filters('the_title',$image->post_title);
//echo '<div class="image image-'.$size.'">'; // thumb needed for galleriffic
if ( $list == 'li') { echo '<li>'; };
if ( $link == 'link') { echo '<a href="'.$atturl.'" class="thumb">'; };
//if ($link == no) {echo 'no link'} ;
//end if;
echo $attimg;
if ( $link == 'link') { echo '</a>'; };
if ( $list == 'li') { echo '</li>'; };
//echo '</div>';
}
}
}
@ms-studio
Copy link
Author

How to use in your theme:

image_toolbox();

This will return all the thumbnails, without any other markup.

image_toolbox('medium',1);

This will return the medium format, and only the first image.

image_toolbox('thumbnail',-1,'link','li');

This will return all images in tumbnail format, and enclose each of them in <li> and <a href> markup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment