本文主要是介绍wordpress相册gallery的几种不同调用方式,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
常规方式调用
if ( $gallery = get_post_gallery( get_the_ID() ) ) :echo $gallery;
endif;
调用循环中的所有图片并可以自字义样式
if ( $gallery = get_post_gallery( get_the_ID(), false ) ) :foreach ( $gallery['src'] AS $src ) {echo '<img src="' . $src . '" class="my-custom-class" alt="Gallery image" />';}
endif;
调用相册的ID
if ( $gallery = get_post_gallery( get_the_ID(), false ) ) :$image_ids = explode( ',', $gallery['ids'] );print_r( $image_ids );
endif;
带描述的相册调用
if ( $gallery = get_post_gallery( get_the_ID(), false ) ) :foreach ( $gallery['src'] as $key => $src ) {echo '<img src="' . $src . '" alt="' . $gallery['caption'][ $key ] . '" />';}
endif;
显示相册图片总数
if ( $gallery = get_post_gallery( get_the_ID(), false ) ) :$total_images = count( $gallery['src'] );echo 'Total Images: ' . $total_images;
endif;
原文
https://www.zhanyes.com/code/6054.html
这篇关于wordpress相册gallery的几种不同调用方式的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!