我有一些帖子,每个帖子包含4个附件图像。我要在我的single.php中执行的操作是使所有4个图像src都无法向每个图像添加不同的类。
<img class="image_1 no_lazy" src="first attached image src"/>
<img class="image_2" src="second attached image src"/>
<img class="image_3" src="third attached image src"/>
<img class="image_4" src="fourth attached image src"/>
这是我尝试过的方法,但是我得到的是数组而不是src ...我想我真的很接近解决方案,但是我找不到我做错了什么...
<?php
global $post;
$args = array(
'post_parent' => $post->ID,
'post_type' => 'attachment',
'post_mime_type' => 'image',
'orderby' => 'menu_order',
'order' => 'ASC',
'numberposts' => 4 );
$images = get_posts($args); ?>
<img class="image_1 no_lazy" src="<?php echo wp_get_attachment_image_src( $images[0]->ID, 'full' ); ?>"/>
<img class="image_2" src="<?php echo wp_get_attachment_image_src( $images[1]->ID, 'full' ); ?>"/>
<img class="image_3" src="<?php echo wp_get_attachment_image_src( $images[2]->ID, 'full' ); ?>"/>
<img class="image_4" src="<?php echo wp_get_attachment_image_src( $images[3]->ID, 'full' ); ?>"/>
有人可以帮我吗?
谢谢
wp_get_attachment_image_url()