Display All Attached Images to a WordPress Post
This will allow you to use Timthumb while showing all images within a WordPress post gallery. In other words, if I upload 4 photos to a post, they will automatically be shown wherever I insert this code in my template, within that post’s loop.
This is assuming that the timthumb script is in your theme’s directory: wp-content/themes/mytheme/timthumb.php
<?php $args = array( 'post_type' => 'attachment', 'orderby' => 'menu_order', 'order' => 'ASC', 'post_mime_type' => 'image' ,'post_status' => null, 'post_parent' => $post->ID ); $attachments = get_posts($args); if ($attachments) { foreach ( $attachments as $attachment ) { ?> <img src="<?php bloginfo('template_url'); ?>/thumb.php?w=200&h=200&zc=1&src=<?php echo wp_get_attachment_url( $attachment->ID , false ); ?>" alt="<?php the_title(); ?>" width="200" height="200" border="0" /> <?php } } ?>
To have each thumbnail link to the full sized original image, have the anchor href point to
<?php echo wp_get_attachment_url( $attachment->ID , false ); ?>



Hey Chad! Great post! Hoping you might be able to help me solve a problem. What if I wanted to use this technique to display all of the attachments of a pages children?
Setting post parent to ‘null’ returns all of the attachments for the site. I’ve also tried get_children to no avail… and the latest attempt was to set ‘post_parent’ => $pageChild->ID,
Currently:
$attachment_args = array(
‘post_type’ => ‘attachment’,
‘numberposts’ => -1,
‘post_status’ => null,
‘post_parent’ => $pageChild->ID,
‘orderby’ => ‘menu_order ID’
);
Thanks in advance!
Marty
Hi Marty, Unfortunately, I’m not able to help you on this one. You might find an answer to that question over at WP Stack Exchange. Be sure to vote up anyone that provides the working answer, and perhaps report back here with your findings.
No worries – was curious if you had it in your bag of tricks
Drop me a note via email if you are interested in WP related project work