Support » Plugin: Easy FancyBox » fancybox for image attachments?

  • Resolved deepbevel


    My thumbnails are linked to attachment pages with medium size images. Can I make the medium size images open in fancybox when clicked, instead of advancing to the next image?


Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Author RavanH


    I’m not really clear on what you want exactly but links to attachment pages will not open in a lightbox overlay. You need to link your thumbnail images directly to the medium or large image file instead. WordPress gives you that option when inserting or editing them in the post content.

    I could include a feature to override all thumbnails linked to attachment pages to automatically open directly in FancyBox instead of going to the attachment page but it will take some considerable effort. If I do that, it will probably go into the Pro version 🙂

    Actually I made it work:

    in attachment.php I removed

    	// If there is more than 1 image attachment in a gallery
    	if ( count( $attachments ) > 1 ) {
    		if ( isset( $attachments[ $k ] ) )
    			// get the URL of the next image attachment
    			$next_attachment_url = get_attachment_link( $attachments[ $k ]->ID );
    			// or get the URL of the first image attachment
    			$next_attachment_url = get_attachment_link( $attachments[ 0 ]->ID );
    	} else {
    		// or, if there's only 1 image attachment, get the URL of the image
    		$next_attachment_url = wp_get_attachment_url();

    and only left this

    // or, if there's only 1 image attachment, get the URL of the image
    		$next_attachment_url = wp_get_attachment_url();

    So now if I tell Easy Fancy Box to open all image links it works on the attachment image too, instesd of advancing to the net image when clicked. Depending on the admin settings fancybox can open the images automatically or manually, like ussual. I have it set to manual at the moment.

    I’m using Cleaner Gallery to make the thumbnail titles show as captions, which link to attachment pages. The thumbs themselves open in fancy box.


    Plugin Author RavanH


    OK, now I understand what you meant… Great solution. Thanks for sharing 🙂

    My pleasure, thanks. However it’s too bad attachment navigation doesn’t seem to work in overlays.

    Plugin Author RavanH


    For the gallery function in FancyBox to work, direct links to each image (not attachment page) in the gallery need to be on the same page. This is not the case on a single attachment page but it IS the case on

    Click any thumbnail to open the image in an overlay (the title link will open a new attachment page) and then you will be able to browser though the gallery with the next/prev buttons (or keyboard keys or even mouse wheel) …

    Yep, that’s what I have. And it’s fine so thanks again.

    What is going on with attachment navigation, where it can’t show any navigation beyond the standard WP previous-next? Do you know if there’s any method or plugin which can have a list of attachment links in the sidebar, and have them open within an attchment page?

    Plugin Author RavanH


    I don’t know about any plugin that can do this for you but since you are using a custom attachment.php already (please keep in mind that any changes will be overwritten when your theme gets updated!) you might be able to insert hidden links to all attached images at once. FancyBox will be able to recognize these hidden links and use them in a gallery…

    The variable $attachments (if > 1) already holds references to all attached images in the gallery so you can use that in a foreach (use get_attachment_link( $attachments[ $key ]->ID ) to get the actual links) to to loop through them and create your hidden links. If you integrate this with the actual output of the current attachment, it should even respect the order of the gallery.

    The output you are aiming for would be something like:

    <a href=""></a>
    <a href=""></a>
    <a href=""><img src="" /></a>
    <a href=""></a>

    Where in this example, the third image is the one that is currently opened in the attachment page. The visitor will be able to click the thumbnail to open the full image in FancyBox. And FancyBox knows what to do with the rest of the image links that are hidden from the visitors view because they have no anchor: they will be accessible via the gallery next/prv buttons in FancyBox…

    Just to give you an idea 🙂

    Yikes, thank you. I don’t know that I can follow this, I wouldn’t know how/where to use a “foreach” in the attachment template. I know that has something to do with the loop, and applying code to each post instead of the whole page. But I don’t know how to set that up in attachments.php,nor would I know if the links you show are to replace or be added to existing code, much less what code!

    perhaps I’ll have a trial and error session with this at some point. Maybe I can figure out what’s going on.

    I also have to learn how to do child-themes!

    Thanks again.

    I’m using a new attachment template with includes this code:

    div class="entry-attachment">
    <a<?php	 	if ( wp_attachment_is_image() ) : ?>
    <?php	 	 endif; ?> href="<?php echo wp_get_attachment_url(); ?>" title="<?php the_title_attribute(); ?>" rel="attachment">
    <?php if ( wp_attachment_is_image() ) : ?>
    <?php $attachment_width  = apply_filters( 'attachment_size', 650 );
    $attachment_height = apply_filters( 'attachment_height', 500 );
    echo wp_get_attachment_image( $post->ID, array( $attachment_width, $attachment_height ) ); ?></a></p>
    <?php else : ?>
    <?php echo basename( get_permalink() ); ?>
    <?php endif; ?>
    </div><!-- .entry-attachment -->

    How might I make my image attachments use fancybox? is there perhaps a way I can add a filter or class for it?

    actually, the attachments are trying to use fancybox, but only the overlay appears, no image:(

    the site

    Okay, if I turn off the overlay, the images appear. bummer, always liked the overlay…

    Plugin Author RavanH


    From my side, it seems to be working…

    Just fixed itself. No idea how. Thanks for checkin..

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘fancybox for image attachments?’ is closed to new replies.