Advertisement:

Author Topic: how can i give a different style only to the first item of items loop ?  (Read 101 times)

elizabeth

  • Newbie
  • *
  • Posts: 37
Hi again dears. As my title describes, how can i give a specific class only to the first item of items loop ?

WEBmods

  • Hero Member
  • *****
  • Posts: 840
  • aka patrickFromCroatia | Osclass Dev Services
Hello,

Before item loop (while(osc_has_items())) you can define a counter variable ($my_counter = 0) and increase its value at the start of the item loop (while(osc_has_items()) { $my_counter++; }).

Then you can check if the counter is 1 (if($my_counter == 1)) and echo the class.

Code: [Select]
<?php
/* Some code... */
$my_counter 0;
while(
osc_has_items()) {
    
$my_counter++; ?>

    <div<?php if($my_counter == 1) { echo ' class="first_item"'; } ?>>
        <?php /* Item data code... */ ?>
    </div>
    <?php
}

Regards.

elizabeth

  • Newbie
  • *
  • Posts: 37
Thank you so much Patrick. You re the best !!! Really... :-* :-* :-*

WEBmods

  • Hero Member
  • *****
  • Posts: 840
  • aka patrickFromCroatia | Osclass Dev Services
You're welcome. :)