是的,这很有帮助。我注意到该功能在标准帖子上运行得非常好。我基本上把函数移到了函数中。php:
function get_rental_carousel_images($rental_id) {
// loosely based on http://martyspellerberg.com/2011/11/outputting-the-wordpress-attachments-gallery/
global $rental;
$images = get_children( array(
\'post_parent\' => $rental_id,
\'post_status\' => \'inherit\',
\'post_type\' => \'attachment\',
\'post_mime_type\' => \'image\',
\'order\' => \'ASC\',
\'orderby\' => \'menu_order ID\'
) );
if ($images) :
foreach ($images as $attachment_id => $image) :
$img_url = wp_get_attachment_url( $image->ID );
?>
<img src="<?php echo $img_url; ?>" />
<?php endforeach; ?>
<?php endif;
然后在我的模板中输出图像,如下所示:
<?php get_rental_carousel_images( get_the_ID() ); ?>