• Resolved bigskydj09

    (@bigskydj09)


    Hi Everyone!

    I am nearly there but need the help of the community to bring me home! I am linking from a “gallery overview” page (thumbnail grid) to a single, full-size image page (attachment.php). The user should then be able to scroll through the remaining attached images using flexslider. So far, this is all working correctly—in principle.

    The problem is that the thumbnail link takes brings the user to the FIRST image in the gallery, rather than the actual image represented by the thumbnail. My attachment.php code is as follows:

    <div id="slider" class="slider">
    	<ul class="slides-init">
    <?php
                global $post;
                $args = array(
                    'post_type' => 'attachment',
                    'numberposts' => -1,
                    'post_status' => null,
                    'post_parent' => $post->post_parent,
                    'order_by' => 'menu_order',
                    'order' => 'ASC'
                );
                $attachments = get_posts($args);
                if ($attachments) {
                    foreach ($attachments as $attachment) {
                        echo '<li>';
                        echo wp_get_attachment_image($attachment->ID, 'large');
                        echo '</li>';
                    }
                }
    ?>
    	</ul>
    </div>

    Any help would be greatly appreciated. Also, the test site can be found here (simply click on one of the thumbnails to see what I mean):

    https://www.adamprince.us/clients/mcnairevans/projects/confessions-for-a-son/

    Many thanks!!!

Viewing 1 replies (of 1 total)
  • Thread Starter bigskydj09

    (@bigskydj09)

    Resolved: The answer was to assign a count to each attachment:

    $args = array(
    		'post_type' => 'attachment',
    		'numberposts' => -1,
    		'post_status' => null,
    		'post_parent' => $post->ID,
    		'order_by' => 'menu_order',
    		'order' => 'DESC'
    	);
    
    	$attachments = get_posts( $args );
    		if ( $attachments ) {
    		$count = 0;
    			foreach ($attachments as $attachment) {
    				$link = get_permalink($attachment->ID);
    				$link = add_query_arg('img',$count,$link);
    					echo '<div class="thumbnail">';
    					echo '<a href="'.$link.'" >';
    					echo wp_get_attachment_image( $attachment->ID, 'small' );
    					echo '</a>';
    					echo '</div>';
    					$count++;
    			}
    		}

    And then link up with that on attachment page.

Viewing 1 replies (of 1 total)
  • The topic ‘attachment.php template and flexslider—linking to specific image’ is closed to new replies.