【发布时间】:2018-04-17 08:37:18
【问题描述】:
我有以下 HTML(+ ACF 字段)用于 Wordpress 中的平滑滑块:
<?php if (have_rows('videofeed2','option')): ?>
<div class="slider-popular">
<?php while (have_rows('videofeed2','option')) : the_row(); ?>
<div class="slider-go-wrap">
<div class="pop-title desktop-title">
<div class="video-title-wrap">
<h2><?php the_sub_field('video_title','option'); ?></h2>
<div class="pop-dura"><?php the_sub_field('date','option'); ?></div>
</div>
</div>
<div class="the-video-area">
<div class="js-lazyYT youtube" data-youtube-id="<?php the_sub_field('youtube_id','option'); ?>" data-width="300" data-height="200"></div>
</div>
<div class="pop-title mobile-pop-title">
<h2><?php the_sub_field('video_title','option'); ?></h2>
<div class="pop-dura"><?php the_sub_field('date','option'); ?></div>
</div>
<div class="video-controls">
<div class="prev-title-popular">
<span class="video-nav-title">Previous video</span>
<span class="lightspan controltitles prev-videotitle">Making a powerful difference</span> <!-- previous video ACF field "title" here -->
<span class="lightspan durations prev-dura">(3:44)</span> <!-- prev video ACF field "dura" here -->
</div>
<div class="next-title-popular">
<span class="video-nav-title">Next video</span>
<span class="lightspan controltitles next-videotitle">Making a powerful difference</span><!-- next video title here -->
<span class="lightspan durations next-dura">(3:44)</span> <!-- next video duration here -->
</div>
</div>
</div>
<?php endwhile;?>
</div>
<?php endif; ?>
视频标题和时长使用 ACF 字段(选项页面)作为内容:
<?php the_sub_field('video_title','option'); ?>
and
<?php the_sub_field('dura','option'); ?>
我想从上一个和下一个字段中获取 ACF 数据到当前幻灯片中的相应字段。我还没有在网上找到任何好的解决方案,可以用一些 jQuery 来完成吗?
【问题讨论】:
-
其实你不会直接得到
ACF data from the previous and next fields。您可以简单地获取上一张/下一张幻灯片的持续时间,并将它们放入当前幻灯片上光滑的beforeChange或afterChange。 -
我的错,完全有可能在循环中直接获取 ACF 数据。您必须从具有上一个/下一个索引的行中检索 ACF。如此处所述:support.advancedcustomfields.com/forums/topic/…。两种方法都可以,恕我直言,服务器端可能是一种更清洁的方法。
标签: javascript php jquery advanced-custom-fields slick.js