There is a plugin I wrote before. This changes the prev/next link to the same order as album view.
Still need some more work to make this better but you can give a try if you like:
<?php
/*
Plugin Name: Image sort
Plugin URI:
Description: Fix prev/next image order as set in [gallery]
Author: yoshi
Version: 0.1
Author URI:
*/
function imgsort_previous_image_link() {
imgsort_adjacent_image_link(true);
}
function imgsort_next_image_link() {
imgsort_adjacent_image_link(false);
}
function imgsort_adjacent_image_link($prev = true) {
global $post;
global $imgsort_order, $imgsort_orderby;
if ($imgsort_orderby == '' && isset($_GET['imgsort_orderby'])) {
$imgsort_orderby = sanitize_sql_orderby( $_GET['imgsort_orderby'] );
}
if ($imgsort_order == '' && isset($_GET['imgsort_order'])) {
$imgsort_order = sanitize_sql_orderby( $_GET['imgsort_order'] );
}
$orderby = $imgsort_orderby ? $imgsort_orderby : 'menu_order ID';
$order = $imgsort_order ? $imgsort_order : 'ASC';
$post = get_post($post);
$attachments = array_values(get_children( array('post_parent' => $post->post_parent, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) ));
foreach ( $attachments as $k => $attachment )
if ( $attachment->ID == $post->ID )
break;
$k = $prev ? $k - 1 : $k + 1;
if ( isset($attachments[$k]) )
echo wp_get_attachment_link($attachments[$k]->ID, 'thumbnail', true);
}
add_filter('attachment_link', 'imgsort_attachment_link', 10, 2);
function imgsort_attachment_link ($link, $id) {
global $imgsort_order, $imgsort_orderby;
if ($imgsort_order)
$link .= (strpos($link, '?') ? '&' : '?') . "imgsort_order=$imgsort_order";
if ($imgsort_orderby)
$link .= (strpos($link, '?') ? '&' : '?') . "imgsort_orderby=$imgsort_orderby";
return $link;
}
add_filter('post_gallery', 'imgsort_gallery_set_order', 10, 2);
function imgsort_gallery_set_order ($content, $attr) {
global $imgsort_order, $imgsort_orderby;
if ( isset( $attr['orderby'] ) )
$imgsort_orderby = sanitize_sql_orderby( $attr['orderby'] );
if ( isset( $attr['order'] ) )
$imgsort_order = sanitize_sql_order( $attr['order'] );
return;
}
After activating this, you need to edit your image.php template and replace <?php previous_image_link() ?>
with <?php imgsort_previous_image_link() ?>
, and <?php next_image_link() ?>
with <?php imgsort_next_image_link() ?>
.