Php 从Wordpress Gallery图像中获取图像标题 “class=”我的自定义类“alt=”画廊图像“/>
上面的代码从名为“gallery”的自定义帖子中提取WordPress gallery。然后它存储并显示图像。有没有办法也将gallery的标题存储到变量中?您可以使用以下代码从WordPress gallery获取图像标题Php 从Wordpress Gallery图像中获取图像标题 “class=”我的自定义类“alt=”画廊图像“/>,php,wordpress,Php,Wordpress,上面的代码从名为“gallery”的自定义帖子中提取WordPress gallery。然后它存储并显示图像。有没有办法也将gallery的标题存储到变量中?您可以使用以下代码从WordPress gallery获取图像标题 <?php $loop = new WP_Query( array( 'post_type' => 'gallery', 'posts_per_page' => 100 ) ); while (
<?php $loop = new WP_Query( array( 'post_type' => 'gallery',
'posts_per_page' => 100 )
);
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php if ( get_post_gallery() ) :
/* Loop through all the image and output them one by one */
foreach( $gallery['src'] as $src ) : ?>
<img src="<?php echo $src; ?>" class="my-custom-class" alt="Gallery image" />
<?php
endforeach;
endif;
endwhile; wp_reset_query(); ?>
“class=”我的自定义类“alt=”画廊图像“/>
您可以使用以下代码从WordPress多媒体资料中获取图像标题
<?php $loop = new WP_Query( array( 'post_type' => 'gallery',
'posts_per_page' => 100 )
);
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php if ( get_post_gallery() ) :
/* Loop through all the image and output them one by one */
foreach( $gallery['src'] as $src ) : ?>
<img src="<?php echo $src; ?>" class="my-custom-class" alt="Gallery image" />
<?php
endforeach;
endif;
endwhile; wp_reset_query(); ?>
“class=”我的自定义类“alt=”画廊图像“/>