I have next/previous links in my image.php and attachment templates:
<?php previous_image_link( false, 'Previous Image' ); ?>
<?php next_image_link( false, 'Next Image' ); ?>
When I create a gallery and click on the image, these links bring me to images which I did not insert into the gallery for that specific post.
I am seeking a code which makes the next/previous links only link to the appropriate next/previous image in the gallery used on that specific parent post. I am seeking a code, not a plugin.
Check [[LINK href="http://wordpress.stackexchange.com/questions/82970/gallery-inside-one-post"]]this post[[/LINK]] at Stackexchange. That solution should work for you as well.
Actually, that question <strong>was posted by me </strong>and the solution does not work!
Did you try with attachments images of specific post.
some thing like this:
// code copied from adjacent_image_link() in wp-include/media.php
$attachments = array_values(get_children( array('post_parent' => $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 )
$next_url = isset($attachments[$k+1]) ? get_permalink($attachments[$k+1]->ID) : get_permalink($attachments->ID);