在 wordpress 中获取图片附件 url 有点麻烦。到目前为止,这是我的代码:
<?php // find images attached to this post / page.
global $post;
$thumb_ID = get_post_thumbnail_id( $post->ID );
$args = array(
'post_type' => 'attachment',
'post_mime_type' => 'image',
'numberposts' => -1,
'orderby' => 'menu_order',
'order' => 'ASC',
'exclude' => $thumb_ID,
'post_parent' => $post->ID
);
$images = get_posts($args);
?>
<?php // Loop through the images and show them
if($images)
{
foreach($images as $image)
{
echo wp_get_attachment_image_url($image->ID, $size='attached-image');
}
}
?>
什么都不返回。如果我换掉这个wp_get_attachment_image_url($image->ID, $size='attached-image');
工作wp_get_attachment_image($image->ID, $size='attached-image');
正常,但会带来图像而不仅仅是 url。