WordPress.org

Forums

[resolved] Need Some Help Looping Through Images (2 posts)

  1. imagebox
    Member
    Posted 4 years ago #

    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

  2. imagebox
    Member
    Posted 4 years ago #

    Nevermind I took a different route.

Topic Closed

This topic has been closed to new replies.

About this Topic