高级自定义字段数据未显示在Wordpress中的Fancybox中

时间:2014-07-31 22:56:58

标签: javascript jquery wordpress fancybox advanced-custom-fields

我使用Wordpress中的高级自定义字段插件输出带有链接的图像(也用于为自定义视频播放器添加嵌入代码)到存档页面上的帖子中。自定义字段的输出代码放在隐藏的div中,然后在单击.watchsession链接时在fancybox中加载。问题是,ACF内容在调用时不会加载到fancybox中。如果我将代码放在它显示的隐藏div之外。不知道我哪里出错了。代码如下!

干杯,

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>    

<a id="fancybox-button" href="#fancybox-content" class="watchsession" title="<?php the_title(); ?>">Watch</a>
<div style="display: none;">
   <div id="fancybox-content" style="width:600px; height:400px;overflow: hidden;">
   <img src="<?php the_field('upload_screenshot'); ?>"/>
   </div>
</div>
</article>

<script type="text/javascript">
                    ( function($) {
$(document).ready(function() {
    $("#fancybox-button").fancybox({
helpers : {
        title : {
            type: 'inside',
            position : 'top'
        }
    },
        'transitionIn'  : 'elastic',
        'transitionOut' : 'elastic',
    });
});
    } ) ( jQuery );
</script>

1 个答案:

答案 0 :(得分:0)

想出来,需要为每个帖子提供一个唯一的ID,所以将打开链接的href更改为fancybox中的post id和div id并修复它!

干杯