How to enable next/prev with prettyPhoto when links are within <li>

Quad6 picture Quad6 · Jan 31, 2013 · Viewed 12.5k times · Source

I have a gallery with the following markup:

<ul>
<li>
    <figure>
        <a href="myimg1.jpg" rel="prettyPhoto"><img src="thumb1.jpg" /></a>
        <figcaption>
        some stuff here
        </figcaption>
    </figure>
</li>
<li>
    <figure>
        <a href="myimg2.jpg" rel="prettyPhoto"><img src="thumb2.jpg" /></a>
        <figcaption>
        some stuff here
        </figcaption>
    </figure>
</li>
</ul>

As far as I can tell, for the automated next/previous navigation to work, the image links need to be beside each other in the DOM. Is there any easy way to get it to work with the above structure? I looked over the options but couldn't see anything obvious.

Answer

nick_w picture nick_w · Feb 14, 2013

All I did to get this working was to modify the rel attribute of the images, so this:

<a href="myimg1.jpg" rel="prettyPhoto"><img src="thumb1.jpg" /></a>
<a href="myimg2.jpg" rel="prettyPhoto"><img src="thumb2.jpg" /></a>

Becomes this:

<a href="myimg1.jpg" rel="prettyPhoto[gallery_name]"><img src="thumb1.jpg" /></a>
<a href="myimg2.jpg" rel="prettyPhoto[gallery_name]"><img src="thumb2.jpg" /></a>

Doing so got me the next/previous controls. I found the details for this on the prettyPhoto home page.

My Javascript was this:

$(document).ready(function () {
    $("a[rel^='prettyPhoto']").prettyPhoto({
        theme: 'facebook',
        slideshow: 5000,
        autoplay_slideshow: false
    });
});