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) containing a slideshow. The user should then be able to use flexslider to scroll through the additional attached images. So far, this is all working correctly—in principle.
The problem is that clicking on any thumbnail 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):
/
Many thanks!!!
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) containing a slideshow. The user should then be able to use flexslider to scroll through the additional attached images. So far, this is all working correctly—in principle.
The problem is that clicking on any thumbnail 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):
http://www.adamprince.us/clients/mcnairevans/projects/confessions-for-a-son/
Many thanks!!!
Share Improve this question asked Aug 6, 2014 at 21:52 AdamAdam 1 2- How to get flex slider to go to a specific slide at the start is offtopic, as it's a javascript question not a WordPress question. Unless this question is how to retrieve the post ID of the current linked to attachment? You can then take that ID and put it somewhere your javascript can find and then use that to set your slide ( something you would ask somewhere else, e.g. stack overflow ) – Tom J Nowell ♦ Commented Aug 6, 2014 at 23:09
- Tom, it turns out it is a bit of both, but your point is well taken. Anyway, I have figured it out! – Adam Commented Aug 7, 2014 at 22:04
1 Answer
Reset to default 0The 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 using the assigned number.