A Way to Feature the First Listing
2 posts by 2 authors in: Forums > CMS Builder
Last Post: June 12, 2009 (RSS)
By zip222 - June 12, 2009
I have a list page where I want to apply a unique css class to only the very first listing.
I am just using a basic foreach loop at the moment...
I want to wrap an extra <div> around the very first listing. Can you suggest a way to do this?
I am just using a basic foreach loop at the moment...
<?php foreach ($listingRecords as $record): ?>
<h3><?php echo $record['title'] ?></h3>
<h4><?php echo $record['year'] ?></h4>
<?php echo $record['introduction'] ?>
<?php endforeach; ?>
I want to wrap an extra <div> around the very first listing. Can you suggest a way to do this?
Re: [jdancisin] A Way to Feature the First Listing
By Damon - June 12, 2009
Hi,
Try adding a counter and then setting the results based on the counter number.
The counter starts at 1. Using an IF statement, you check if the counter equals 1 and if it does, output the code with the div tags.
If the counter doesn't equal 1, then it outputs the other code without the div tag.
Hope this helps.
Try adding a counter and then setting the results based on the counter number.
The counter starts at 1. Using an IF statement, you check if the counter equals 1 and if it does, output the code with the div tags.
If the counter doesn't equal 1, then it outputs the other code without the div tag.
<?php $counter = 1 ?>
<?php foreach ($listingRecords as $record): ?>
<?php if($counter == 1) : ?>
<div class="ClassNameHere">
<h3><?php echo $record['title'] ?></h3>
<h4><?php echo $record['year'] ?></h4>
<?php echo $record['introduction'] ?>
</div>
<?php else : ?>
<h3><?php echo $record['title'] ?></h3>
<h4><?php echo $record['year'] ?></h4>
<?php echo $record['introduction'] ?>
<?php endif; ?>
<?php $counter++ ?>
<?php endforeach; ?>
Hope this helps.
Cheers,
Damon Edis - interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Damon Edis - interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/