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 Link to comment https://forums.phpfreaks.com/topic/249921-standard-loop/ 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 Link to comment https://forums.phpfreaks.com/topic/249921-standard-loop/#findComment-1282711 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); } Link to comment https://forums.phpfreaks.com/topic/249921-standard-loop/#findComment-1282783 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? Link to comment https://forums.phpfreaks.com/topic/249921-standard-loop/#findComment-1283187 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.