detecting first record listed in any sort

5 posts by 4 authors in: Forums > CMS Builder
Last Post: October 11, 2009   (RSS)

By rez - October 9, 2009 - edited: October 9, 2009

I have a <ul> list and the first <li> looks like this:

<li class="first-item">

the rest are just <li>


So, to make this with CMS builder, i want to put an if statement in there:

<li<if this is the first record> class="first-item"<endif>>


My records are currently sorted by decending order. So the first record in the list is the highest number record. (or do the record number change when dragged in the editor?)

How do I make the if statement detect whatever the first item in my ul? I hope there is a universal way that will work no matter how i sort (but I want this to work either way and can't figure it out). I need this to work in several sorting ways, like:

decending order, ascending order, and drag sort order.

I gave up on it and deleted my code, making all my records look the same without the "first-item" class. I hope this is easy or I can give it a go again and post my attempts.

Re: [rez] detecting first record listed in any sort

By irelocation - October 9, 2009

I have the same issue, Rez. Anyone have any ideas? I am especially interested in doing it for ascending order....
home security system

Re: [Damon] detecting first record listed in any sort

By rez - October 11, 2009 - edited: October 11, 2009

Ah ha. Brilliant. You can treat any number.

While we are on the subject, how would you find the last one in a consistent way?

:)

Re: [rez] detecting first record listed in any sort

By Chris - October 11, 2009

Hi rez,

Here you go:

<ul>
<?php $counter = 1; ?>
<?php foreach ($inventoryRecords as $record): ?>
<?php if ($counter == 1): ?>
<li class="first-item"><?php echo $record['name'] ?></strong></li>
<?php elseif ($counter == sizeof($inventoryRecords)): ?>
<li class="last-item"><?php echo $record['name'] ?></strong></li>
<?php else: ?>
<li><?php echo $record['name'] ?></li>
<?php endif; ?>
<?php $counter++ ?>
<?php endforeach; ?>
</ul>


I hope this helps. Please let me know if you have any questions.
All the best,
Chris