Displaying all images from a WordPress post

前端 未结 5 1507
一整个雨季
一整个雨季 2020-12-09 23:36

I have this piece of code I found on some blog, that\'s supposed to display all images from a WordPress post.

function getImage() {
    global $more;
    $m         


        
5条回答
  •  醉梦人生
    2020-12-10 00:17

    its easier now with the new wordpress get_attached_media($type,$post) function

    $attachments= get_attached_media( 'image', $post->ID );
    foreach($attachments as $att_id => $attachment) {
      $full_img_url = wp_get_attachment_url($attachment->ID);
    // You can echo it out here
    }
    

    note that this gets only the files uploaded to the post . not files added through media library.

提交回复
热议问题