I am using Wordpress Gallery shortcode and I was wondering if there is a way to navigate using the arrow keys? Like if I view an single image and used the right arrow to navigate to the next image in the gallery set. Any idea how to do this?
The Underscores (_s) starter theme comes with a keyboard navigation script for this. I haven't tested this myself though. But the JS file looks like this:
It also needs some modifications to your attachment theme file to make the links work correctly. My suggestion is that you download the _s theme and take a look in the image.php file.
Basically what you need on the attachment page is a link to the next/prev image inside an element with the class "previous-image" / "entry-attachment".
I am using standard WP galleries and have each image link to an attachment page where the image is displayed fullsize. To show PREVIOUS and NEXT links in order for the user to get to the corresponding images I found the functions previous_image_link and next_image_link useful.
In my attachment.php I have the following lines to make WordPress display previous/next links:
This results in markup that might look like:
My client wanted to be able to use his keyboard to switch back and forth between the images of any gallery, so I added jzatt's jQuery script and edited it to my footer.php that listens for the KEYDOWN event and, if triggered, grabs the links WP provided and changes the URL of the page.
This is the jQuery script:
What I need to add, though, is an IF statement to first check whether the user is indeed on an attachment page.