Jump to content

Standard loop?


dtek516

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.