dtek516 Posted October 27, 2011 Share Posted October 27, 2011 Hi, I have a simple loop question: I have 5 custom variables that are accessed with: <?php echo get_field('image_1'); ?> they contain a URL as their value. How can I loop through these variables and display this: <a href="<?php echo get_field('image_1'); ?>" rel="lightbox[<?php the_title(); ?>]"><img src="<?php echo get_field('image_1'); ?>"/></a> if the value is true. yet nothing if its not. Thanks Quote Link to comment Share on other sites More sharing options...
dtek516 Posted October 27, 2011 Author Share Posted October 27, 2011 By the way: this is within a wordpress WHILE loop Quote Link to comment Share on other sites More sharing options...
manohoo Posted October 27, 2011 Share Posted October 27, 2011 get_field() is a function, image1 is a parameter. If you have all the parameters in an array then you can loop like this: $images = array('image1', 'image2', 'image3'); foreach ($images as $row) { get_field($row); } Quote Link to comment Share on other sites More sharing options...
dtek516 Posted October 29, 2011 Author Share Posted October 29, 2011 Here's what I've got... <?php for($i=1; $i<6; $i++){ //loop 5 times if(get_field('image_' . $i)){ //check if there is an image on each iteration of the loop echo' <a href="' . get_field('image_' . $i) . '" rel="lightbox[ ]"><img src="' . get_field('image_' . $i) . '"/>'; //output results } } ?> now my problem is adding this: rel="lightbox[<?php the_title();?>]" inside that echo. any idea? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.