使用以下代码执行此工作:
global $post;
$page_id = $post->ID;
$all_attachments = get_posts( array( \'post_type\' => \'attachment\',\'post_mime_type\' => \'image\', \'post_parent\' => $page_id, \'post_status\'=>\'published\', \'numberposts\' => -1 ) );
$no_of_photos = count($all_attachments); // Gets the number of photo\'s attached in $no_of_photos variable
$first_img_URL = get_permalink($all_attachments[0]->ID); // Gets the URL of first attachment in $first_img_URL variable
在上面的代码中,只需将$page\\u id替换为照片附加到的页面/帖子的id。