Getting and Displaying First Attachment
-
I am currently using the following code in functions.php
<?php function postimage($size=medium) { if ( $images = get_children(array( 'post_parent' => get_the_ID(), 'post_type' => 'attachment', 'numberposts' => 1, 'post_mime_type' => 'image',))) { foreach( $images as $image ) { $attachmenturl=wp_get_attachment_url($image->ID); $attachmentimage=wp_get_attachment_image( $image->ID, $size ); echo $attachmentimage; } } else { echo ""; } } ?>
and the following code in my themes template files
<?php postimage('thumbnail'); ?>
in order the last attachment image and display it form the current post. Is there any way that this can be altered slightly in order to display the FIRST attachment added.
I have tried reordering them with the gallery feature but this didn’t work.
Thanks
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Getting and Displaying First Attachment’ is closed to new replies.