Here is an example of functions to get next and previous attached images of the post:
<?php function get_post_next_attached_image( $attachment_id ) { global $wpdb; $attachment = get_post( $attachment_id ); $next_attached_image = $wpdb->get_row("SELECT * FROM " . $wpdb->posts . " WHERE ID = (SELECT MIN(ID) FROM " . $wpdb->posts . " WHERE post_parent = '" . $attachment->post_parent . "' AND post_mime_type LIKE 'image%' AND ID > '" .$attachment_id . "' ORDER BY menu_order, ID);"); return $next_attached_image; } function get_post_previous_attached_image( $attachment_id ) { global $wpdb; $attachment = get_post( $attachment_id ); $previous_attached_image = $wpdb->get_row("SELECT * FROM " . $wpdb->posts . " WHERE ID = (SELECT MAX(ID) FROM " . $wpdb->posts . " WHERE post_parent = '" . $attachment->post_parent . "' AND post_mime_type LIKE 'image%' AND ID < '" .$attachment_id . "' ORDER BY menu_order, ID);"); return $previous_attached_image; } ?> |