Wordpress中的Fancybox编码 - 图像链接

i'm stumped. Firstly this is a Fancybox installed on theme, not a plugin, secondly - i'm still learning - so would super appreciate the help!

Fancybox needs a href link to open/load the images in wordpress post.

I am using "get attached media" to get all images on the post.

Where and how can I create the href link for Fancybox to work within this?

This is the code I am using:

<div class="img_div">

<?php $media = get_attached_media( 'image', $post->ID );
if(! empty($media)){
foreach ( $media as $attachment ) {
    $full = wp_get_attachment_url( $attachment->ID );
    echo '<img class="image-2" data-fancybox="images" src="'.$full.'" alt="'$attachment->post_title'" />';

And this this the Fancybox documentation:

<a href="image.jpg" data-fancybox="images" data-caption="My caption">
<img src="thumbnail.jpg" alt="" />

Any help would be amazing...i'm stumped on this part of the learning curve.

2017/04/15 19:31
  • wordpress
  • fancybox
  • php
  • 点赞
  • 收藏
  • 回答