画廊本质上只是一组附加的帖子,所以。。。
$post_id = 1; // set to your desired parent post
$attachments = new WP_Query(
array(
\'post_parent\' => $post_id, // post to which the gallery is attached
\'post_status\' => \'inherit\',
\'post_type\' => \'attachment\',
\'post_mime_type\' => \'image\',
// \'order\' => $order,
// \'orderby\' => $orderby
)
);
// var_dump($attachments); // debug
foreach ($attachments->posts as $p) {
var_dump($p);
var_dump(wp_get_attachment_image_src($p->ID));
var_dump(get_post_custom($p->ID));
}
您应该能够在转储的数据中找到所有需要的内容,以及更多内容。事实上,我认为您所需要的只是这些转储中的最后两个,因此您可以简化为:
$post_id = 1; // set to your desired parent post
$attachments = new WP_Query(
array(
\'fields\' => \'ids\',
\'post_parent\' => $post_id, // post to which the gallery is attached
\'post_status\' => \'inherit\',
\'post_type\' => \'attachment\',
\'post_mime_type\' => \'image\',
// \'order\' => $order,
// \'orderby\' => $orderby
)
);
// var_dump($attachments);
foreach ($attachments->posts as $ids) {
var_dump(wp_get_attachment_image_src($ids));
var_dump(get_post_custom($ids));
}