我在我的网站上使用了这个部分wp_get_attachment_image_src()
要获取与帖子关联的所有图像,但现在需要获取特定大小(大小:listing\\u grid):
<?php $args = array(
\'post_parent\' => $post->ID,
\'post_type\' => \'attachment\',
\'numberposts\' => 15, // -1, show all
\'post_status\' => \'any\',
\'post_mime_type\' => \'image\',
\'orderby\' => \'menu_order\',
\'order\' => \'ASC\'
);
$images = get_posts($args);
if($images) { ?>
<images>
<?php foreach($images as $image) { ?>
<image><![CDATA[<?php echo wp_get_attachment_url($image->ID); ?>]]></image>
<?php } ?>
</images>
<?php } ?>
最合适的回答,由SO网友:E. Mendes 整理而成
谢谢maverick,你的解决方案很有效
<?php $args = array(
\'post_parent\' => $post->ID,
\'post_type\' => \'attachment\',
\'numberposts\' => 15, // -1, show all
\'post_status\' => \'any\',
\'post_mime_type\' => \'image\',
\'orderby\' => \'menu_order\',
\'order\' => \'ASC\'
);
$images = get_posts($args);
if($images) { ?>
<images>
<?php foreach($images as $image) { ?>
<image><![CDATA[<?php echo wp_get_attachment_image_src( $image->ID, \'listing_gallery_2x\')[0]; ?>]]></image>
<?php } ?>
</images>
<?php } ?>