$post->post_parent, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID') )); foreach ( $attachments as $k => $attachment ) if ( $attachment->ID == $post->ID ) break; $k = $prev ? $k - 1 : $k + 1; if ( isset($attachments[$k]) ) return wp_get_attachment_link($attachments[$k]->ID, 'thumbnail', true); } /** * Create a gallery from post attachements. Overrides WordPress default shortcode post gallery code. * * @param $unused not used, required by filter hook * @param array $attr List of attributes that are populated by post gallery shortcode * @return string Markup to display a gallery * **/ function cfct_post_gallery($unused, $attr) { $id = null; $itemtag = null; $captiontag = null; $columns = null; global $post; // We're trusting author input, so let's at least make sure it looks like a valid orderby statement if ( isset( $attr['orderby'] ) ) { $attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] ); if ( !$attr['orderby'] ) unset( $attr['orderby'] ); } $sc_atts = shortcode_atts(array( 'order' => 'ASC', 'orderby' => 'menu_order ID', 'id' => $post->ID, 'itemtag' => 'dl', 'icontag' => 'dt', 'captiontag' => 'dd', 'columns' => 3, 'size' => 'thumbnail' ), $attr); extract($sc_atts); $id = intval($id); $attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) ); if ( empty($attachments) ) return ''; if ( is_feed() ) { $output = "\n"; foreach ( $attachments as $id => $attachment ) $output .= wp_get_attachment_link($id, $size, true) . "\n"; return $output; } $itemtag = tag_escape($itemtag); $captiontag = tag_escape($captiontag); $columns = apply_filters('cfct_post_gallery_columns', intval($columns)); $itemwidth = $columns > 0 ? floor(100/$columns) : 100; $output = apply_filters('gallery_style', ' \n"; return $output; } add_filter('post_gallery', 'cfct_post_gallery', 10, 2); ?>