0

我想显示附件的实际图像,而不是附件的 url。我正在使用此代码,但它正在显示网址:

 <?php
 $argsThumb = array(
     'order'       => 'ASC',
     'post_type'   => 'attachment',
     'post_parent' => $post->ID,
     'post_status' => null
 );
 $attachments = get_posts($argsThumb);
 if ($attachments) {
     foreach ($attachments as $attachment) {
         apply_filters('the_title', $attachment->post_title);
         echo wp_get_attachment_url($attachment->ID, false, false); 
     }
 }
 ?> 
4

1 回答 1

0

也许尝试以下方法:

 <?php
 $argsThumb = array(
     'order'       => 'ASC',
     'post_type'   => 'attachment',
     'post_parent' => $post->ID,
     'post_status' => null
 );
 $attachments = get_posts($argsThumb);
 if ($attachments) {
     foreach ($attachments as $attachment) {
         apply_filters('the_title', $attachment->post_title);
         echo "<img src='" . wp_get_attachment_url($attachment->ID, false, false) . "' />"; 
     }
 }
 ?> 
于 2013-05-17T08:30:56.290 回答