Thanks for the good words, for your interest in the plugin and for this stimulating question.
The function reference for next_image_link() starts with “This creates a link to the next image attached to the current post.” Since your images are unattached, I’m surprised it works at all. The next_image_link() and previous_image_link() functions both rely on another WordPress function, adjacent_image_link(), which does its own database query (including a post_parent restriction) to compile the list of attachments to work with. You’re getting some good results simply because NONE of your images are attached, so they ALL have post_parent=0. This is not a recipe for success, as you’ve discovered.
WordPress 3.5 introduced the “ids=” parameter, of which the Gallery Shortcode Codex entry says:
Specifying IDs in your shortcode allows you to include images in your gallery that aren’t necessarily “attached” to your post — that is to say, not uploaded from within your post or page. This flexibility allows you to create and embed any number of galleries containing any number of images!
I suspect this, too, breaks the “image_link” functions but I haven’t tested that.
Have you considered using a plugin such as the Photonic Gallery (supported by MLA), the Jetpack by WordPress.com (Carousel, mosaic, circles, squares, and a slideshow view) or JS Shadowbox? All of these support previous/next browsing.
The next Media Library Assistant release will include a new way to separating the data selection and format/display parts of gallery production, so you can use [mla_gallery] to select the attachments you want and then hand off a list of their IDs to any other shortcode that accepts a list of IDs as input. If that’s of interest, it will be out in a week or so.
Finally, I do see that the adjacent_image_link() function ends with a filter that could be used to replace the value it would otherwise return. If you’re tied to using these functions and your own code to control the previous/next functions I can look at somehow using this filter to use the ID list [mla_gallery] generates to return a more accurate result. Let me know if that would be worthwhile.
Hi David, and thank you for the quick, thorough and thoughtful response. Let’s see:
Ideally, I’d like for my client to be able to “create galleries” simply by checking the appropriate boxes for the taxonomy terms upon upload with the Media Library Assistant. It saves a lot of tedious work. It also allows him to check off multiple taxonomy term boxes via this method (hierarchical taxonomy).
The [mla_gallery] shortcode does need to link to an attachment page and not an overlay or other lightbox-type effect, due primarily to the fact that there is additional information on the page (description, location, purchase information, sizing options, etc.)
Before using the MLA Gallery, I simply created galleries via a taxonomy archive page, whereby each tax term displayed thumbnails of all the images in that term. The thumbnail linked to an attachment page (image.php), and this was fine, except navigation was an issue due the problems you already mentioned. I got around this to a certain extent by creating a new function (a modified adjacent_image_link) that used a tax query to pull the next/previous images in the same term (using menu_order to sort). It works great except for the fact that if an image belongs to more than one term, the image.php page doesn’t know which term to use, and results are again unreliable.
I was hoping that the MLA Gallery plugin would somehow allow me to isolate images within a gallery, avoiding the “multiple terms” issue.
I certainly DO NOT expect you to solve this problem for me, but I was curious if perhaps you might have a suggestion that would allow me to plod forward. I really love this plugin, and I think a breakthrough is somewhere close, but I need a nudge 😉
Thank you again, David, for taking the time to reply to my earlier question.
Since you’re comfortable with some PHP coding, here’s one way to proceed. Create a shortcode version of your modified adjacent_image_link function, something like:
[my_adjacent_image ids="1,2,3" my_current_id=2, my_direction=previous]
You can use this shortcode as the display/format half of the gallery and you can use
[mla_gallery]to generate the
[mla_gallery orderby="menu_order, ID ASC" size="thumbnail" post_parent=all tax_query="array(array('taxonomy' => 'image-gallery','field' => 'slug','terms' => 'desert-landscape'))" mla_alt_shortcode=my_adjacent_image my_current_id=2, my_direction=previous]
By the way, in this particular example you could replace the
Your shortcode can return whatever HTML your theme needs. If you want to code a general-purpose
image.phppage, you’ll need a way to pass the taxonomy and term information (maybe more) from the gallery page to the individual image page. There’s an earlier support topic that addresses this:
Look down toward the bottom of that topic for the entry that begins “That’s excellent; we’re in the home stretch!” and read from there.
If the above is incomplete or unclear, let me know and I’ll expand on it. I know we can find a solution that works for you.
Thanks again for your interest and for your perseverance!
Wow, amazing–thank you for the (again) detailed response.
Your suggestion of passing parameters from the gallery page through to the attachment page are precisely what I need. I can then configure my modified function to stay within that term so the tax terms don’t get all jumbled up.
I’m assuming I’d have to pass the same parameter on to the prev/next links as well, so that’s something I’ll try to figure out.
I’m going to read through your suggestions again and see if I can get my bearings. I’m still learning PHP, so each step requires a little perseverance on my part, but I enjoy troubleshooting and making WP do new things.
Basically, my goal is this:
– Set up galleries based on taxonomy terms
– link thumbnails to attachment page
– provide prev/next navigation at the attachment page level, staying within the same term, although many images belong to multiple terms.
If you think it’s possible, I’ll continue forging ahead. Thank you again so much for your patience and willingness to lend a hand!
I am positive your goal can be reached, and I’m glad you are enjoying the journey.
I’m happy to work with you on issues related to your theme and
image.phpcode, but it might be too site-specific for the MLA support forum. If you want to pursue this discussion offline, send me your e-mail address (or telephone number) and I will respond to continue the dialog. Go to the “Contact Us” page at our web site:
Thanks for understanding.
Agreed. Thank you once again for your considerable time put into helping me.
I have released MLA version 1.42, which includes pagination support for the
[mla_gallery]shortcode. Complete information and examples are on the Settings/Media Library Assistant Documentation tab.
I hope the new features will help with the pagination portion of your tasks. Let me know if you have any problems or further questions.
- The topic ‘Next/Previous image link on attachment page (using taxonomies)’ is closed to new replies.