WordPress.org

Ready to get started?Download WordPress

Forums

Easy FancyBox
[resolved] fancybox for image attachments? (14 posts)

  1. deepbevel
    Member
    Posted 2 years ago #

    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?

    thanks!

  2. RavanH
    Member
    Plugin Author

    Posted 2 years ago #

    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 :)

  3. deepbevel
    Member
    Posted 2 years ago #

    Actually I made it work:

    in attachment.php I removed

    $k++;
    	// 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 );
    		else
    			// 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.
    Sample

    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.

    Thanks

  4. RavanH
    Member
    Plugin Author

    Posted 2 years ago #

    OK, now I understand what you meant... Great solution. Thanks for sharing :)

  5. deepbevel
    Member
    Posted 2 years ago #

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

  6. RavanH
    Member
    Plugin Author

    Posted 2 years ago #

    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 http://www.foursticks.net/christophesmith/gallery-2/

    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) ...

  7. deepbevel
    Member
    Posted 2 years ago #

    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?

  8. RavanH
    Member
    Plugin Author

    Posted 2 years ago #

    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="http://url.to/full_image1.jpg"></a>
    <a href="http://url.to/full_image2.jpg"></a>
    <a href="http://url.to/full_image3.jpg"><img src="http://url.to/thumbnail3.jpg" /></a>
    <a href="http://url.to/full_image4.jpg"></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 :)

  9. deepbevel
    Member
    Posted 2 years ago #

    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.

  10. deepbevel
    Member
    Posted 2 years ago #

    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; ?>
    </a>
    </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?
    Thanks!

  11. deepbevel
    Member
    Posted 2 years ago #

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

    the site

  12. deepbevel
    Member
    Posted 2 years ago #

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

  13. RavanH
    Member
    Plugin Author

    Posted 2 years ago #

    From my side, it seems to be working...

  14. deepbevel
    Member
    Posted 2 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic