3 posts by 2 authors in: Forums > CMS Builder
Last Post: April 9, 2015   (RSS)

By KCMedia - April 9, 2015

Hi Guys

i have section that stores testimonials and the issue is that after every 2nd record i need to add a class to the div class. on the Div <div class="one_half  animate" data-anim-type="fadeInLeft" data-anim-delay="100"> i need to add on the class so it is bold text to the right after the 2nd record so record 1 dosnt have it but the 2nd record does. <div class="one_half  last animate" data-anim-type="fadeInLeft" data-anim-delay="100">

                <?php foreach ($testimonials_listPages as $record): ?>
                <div class="one_half  animate" data-anim-type="fadeInLeft" data-anim-delay="100">
                    <div class="box">" <?php echo textLimitTestimonials ($record['content'], 300) ?><br>
                        <a href="<?php echo $record['_link'] ?>" class="button eleven">..read more</a>
                    </div>
                    
                    <div class="who">
                    
                        <?php foreach ($record['logo'] as $index => $upload): ?>
                        <img src="<?php echo $upload['thumbUrlPath'] ?>" alt="<?php echo htmlencode($record['title']) ?>" title="<?php echo htmlencode($record['title']) ?>"/>
                        <?php endforeach ?>
                        <strong><?php echo htmlencode($record['title']) ?></strong>
                        
                    </div>
                </div>
                <?php endforeach ?>

Thanks

Craig
KC Media Solutions
www.kcmedia.biz

By gkornbluth - April 9, 2015

Hi Craig,

Can’t get to testing this right now, but the approach I’d use is to add and increment a counter in your foreach record loop.

Then use an if statement around your <div> tag that looks for a counter value of 2, and if that condition is met, display the special code and reset the counter to a value of 0.

Something like this:

<?php $count = '0' ?>
<?php foreach ($testimonials_listPages as $record): ?>
<?php $count++ ?>
 <?php if($count == 2 ):?>
<?php $count = '0' ?>
<div class="one_half  animate" data-anim-type="fadeInLeft" data-anim-delay="100"> <?php else : ?> <div class="your_other_class”><?php endif ?>
... the rest of your code...


Hope that helps,

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!

Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php