I was originally using a single field and things worked perfectly with the following code. Now I need to alter it to loop of several fields that are similar.
To start: I've created several custom fields on my page (slide1, slide2, slide3) and these fields contain a URL for an image location. Next I created some text fields (slide1_text, slide2_text, etc).
Code wise, I was pulling my fields in my template like:
<?php
// check for slide
$slide = get_post_meta($post->ID, 'slide1', $single = true);
// check for slide text
$thumb_text = get_post_meta($post->ID, 'slide1_label', $single = true);
// if there's a slide
if($slide !== '') { ?>
<section class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
<div class="item active">
<img src="<?php echo $slide; ?>" class="slider-images" />
</div>
<div class="carousel-caption">
<h2><?php if($slide_text !== '') { echo $slide_text; } else { echo the_title(); } ?></h2>
</div>
</div>
</section>
<?php } // end if statement
?>
Basically it checks to see if there is a field called slide1 and if so it prints it. I don't know a lot about adding in loops and the end goal here is to return the fields formatted for a bootstrap carousel. (I know there are plugins but I've tried a couple and they aren't exactly what I want.)
How can I alter this code to include a loop so that it will check and see if there are fields titled slide* and if so, loop over them and get them all?
Additionally, it would be great if there were a way I could ensure the first slide had a class of "active" as you can see in the code below <div class="item active"> and all other fields will only be class=item.