Search
Close this search box.

WordPress eazy image gallery 获取图片集代码

function easy_image_gallery( $gallery_id = 'old_db' ) {

	$galleries = easy_image_gallery_get_galleries();
    global $post;

    if ( isset($galleries) && !empty($galleries) ){
        ob_start();
        foreach ($galleries as $gallery){

            if ($gallery_id == 'old_db'){
                $gallery_id = $gallery['SHORTCODE'];
            }

            if ( $gallery['SHORTCODE'] == $gallery_id ){
                $gallery_exist = true;

                $has_gallery_images = $gallery['DATA'];

                if ( !$has_gallery_images )
                    return;

                // clean the array (remove empty values)
                $has_gallery_images = array_filter( $has_gallery_images );

                // css classes array
                $classes = array();

                // thumbnail count
                $classes[] = $has_gallery_images ? 'thumbnails-' . easy_image_gallery_count_images( $gallery['SHORTCODE'], $gallery ) : '';

                // linked images
                if ( isset($gallery['OPEN_IMAGES']) && $gallery['OPEN_IMAGES'] == 'on' ){
                    $classes[] = 'linked';
                }

                $classes = implode( ' ', $classes );
    			if ( isset($has_gallery_images) && !empty($has_gallery_images) ) {
					?>
                    <?php
					    $newarrayImg=[];
                    	foreach ( $has_gallery_images as $attachment_id ) {
	                        $image_link	= wp_get_attachment_image_src( $attachment_id, apply_filters( 'easy_image_gallery_linked_image_size', 'large' ) );
							array_push($newarrayImg,$image_link);
	                    }
            	}
            }
        }

        $eig_gallery = ob_get_clean();
        return apply_filters( 'easy_image_gallery', $newarrayImg );
    }
}




前端调用方法:


<div class="swiper-wrapper">
                           <?php
                              $news = easy_image_gallery();
                              foreach ($news as $kv){
                                  ?>
                                  <div class="swiper-slide">
                                      <a href="<?php echo $kv[0];?>" data-fancybox="gallery"><img src="<?php echo $kv[0];?>" width="500" /></a>
                                  </div>
                                  <?php
                              }
                            ?>   
                          </div>












发表评论

Optimized by WPJAM Basic