WordPress.org

Support

Support » Themes and Templates » [Resolved] Need Some Help Looping Through Images

[Resolved] Need Some Help Looping Through Images

  • I have created a custom field called collection_image_child which stores a URL to an image and I have created the following code to display it within the theme:

    <?php if ( get_post_meta($post->ID, 'collection_image_child', true) ) { ?>
    									<a class="productimage" href="<?php echo get_post_meta($post->ID, "collection_image_child", $single = true); ?>"><img src="<?php bloginfo('template_directory'); ?>/includes/timthumb.php?src=<?php echo get_post_meta($post->ID, "collection_image_child", $single = true); ?>&w=25&a=t" alt="<?php the_title(); ?>" width="25" /></a>
    						<?php } ?>

    My question is, if I have multiple instances of the custom field collection_image_child on a post, how can I loop through to display all of them?

    I tried creating a while loop, but I think I got it wrong because it just ended in an infinite loop showing the images over and over again.

    <?php while ( get_post_meta($post->ID, 'collection_image_child', true) ) { ?>
    									<a class="productimage" href="<?php echo get_post_meta($post->ID, "collection_image_child", $single = true); ?>"><img src="<?php bloginfo('template_directory'); ?>/includes/timthumb.php?src=<?php echo get_post_meta($post->ID, "collection_image_child", $single = true); ?>&w=25&a=t" alt="<?php the_title(); ?>" width="25" /></a>
    						<?php } ?>

    Thanks,

    Chad

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘[Resolved] Need Some Help Looping Through Images’ is closed to new replies.
Skip to toolbar