Swipebox和wordpress循环

时间:2015-09-09 09:33:16

标签: php wordpress loops advanced-custom-fields

我正在使用Swipebox for Advanced Custom Fields gallery字段在灯箱中显示图像。画廊是通过按钮激活的,一页上有多个画廊(它们是循环的)。

    <?php $i = 1;  ?>                      
<?php
    $loop = new WP_Query( array( 'post_type' => 'objektid') );
    if ( $loop->have_posts() ) :
        while ( $loop->have_posts() ) : $loop->the_post(); ?>
        <div class="objektid_wrap">
                <div class="right">
                    <div class="right_content">
                        <h2><?php echo get_the_title(); ?></h2>
                                                            <?php 
                    $images = get_field('gallery');
                        if( $images ): ?>
                          <?php foreach( $images as $image ): ?>
                            <a class="thumb-link swipebox" href="<?php echo $image['url']; ?>" title="<?php echo $image['title']; ?>"><button>Vaata galeriid</button></a>
                          <?php endforeach; ?>
                    <?php endif; ?>
                    </div>
                </div>
                <div class="left">
                <?php if ( has_post_thumbnail() ) { ?>
                <?php the_post_thumbnail(); ?>
                <?php } ?>
                </div>
                </div>
                <?php    if( $i == 2) {
                    echo '<div class="arrow_box"><span class="ion-chevron-down"></span></div>';
                    } else {
                    echo '';
                    }  ?>
        <?php $i++; endwhile;
             if (  $loop->max_num_pages > 1 ) : ?>
             <?php endif;
    endif;
?> 

虽然swipebox在灯箱中查看时会合并所有图库图像。画廊从正确的幻灯片(例如第二个画廊)开始,但它包含所有幻灯片,包括第一个幻灯片。我的想法是,当循环第二个图库时,如何为swipebox实现刷新/重新初始化?

修改

Swipebox通过rel =“gallery-1”等分隔画廊。 一种方法是动态地将rel =“gallery-x”添加到每个幻灯片包

<div class="objektid_wrap">
<a class="thumb-link swipebox" rel="gallery-1"..
<a class="thumb-link swipebox" rel="gallery-1"..
</div>

<div class="objektid_wrap">
<a class="thumb-link swipebox" rel="gallery-2"..
<a class="thumb-link swipebox" rel="gallery-2"..
</div>

有关实现这一目标的任何想法吗?

最好的愿望

1 个答案:

答案 0 :(得分:0)

通过将rel="gallery-<?php echo $i ?>"添加到

来解决
 <a class="thumb-link swipebox" href="<?php echo $image['url']; ?>" title="<?php echo $image['title']; ?>"><button>Vaata galeriid</button></a>