How to use ‘get attached media’ with a custom fancybox?
-
Hi,
I’m quite new to much of this, but so far going ok…but really held up on a snag.
I’m stuck on getting my images within my post to appear properly in a fancybox lightbox (which is installed on my theme, not a plugin).
I am using the “get_attached_media”, along with the shortcode “data-fancybox=”images”” ….images appear all well and good on the page, but on clicking them lightbox appears as the overlay, but doesn’t load the images.
I’m sure i’m doing something fundamental and basic wrong – if anybody can see what it is that would be awesome
This is the code I am currently using on my single page:
<div class="img_div"> <?php $media = get_attached_media( 'image', $post->ID ); if(! empty($media)){ foreach($media as $media_id => $media_file){ $full = wp_get_attachment_url( $media_id ); echo '<img class="image-2" data-fancybox="images" src="'.$full.'" alt="'.$media_file->post_title.'" />'; } } ?> </div>
and if it helps…this are the directions from Fancybox documentation…what it should look like if it were static html:
<a href="image.jpg" data-fancybox="images"> <img src="thumbnail.jpg" /> </a>
- The topic ‘How to use ‘get attached media’ with a custom fancybox?’ is closed to new replies.