Keyword

even/odd in lists flawed - fix

  • Ralf Longwitz
  • Ralf Longwitz's Avatar Topic Author
  • Offline
  • Junior Member
More
11 years 7 months ago - 11 years 7 months ago #110609 by Ralf Longwitz
even/odd in lists flawed - fix was created by Ralf Longwitz
Extra fields are nicely lined in a list. And "even" and "odd" are added as classes to each line. Unfortunately this does not work well as soon as some of the fields are ommitted because they are empty.

The reason is the code in .\components\com_k2\templates\default\item.php, around line 254:
<?php foreach ($this->item->extra_fields as $key=>$extraField): ?>
<?php if($extraField->value != ''): ?>
<li class="<?php echo ($key%2) ? "odd" : "even"; ?> type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?>">

Fix (whole <ul>):
<ul>
                        <?php $evenodd = 0; foreach ($this->item->extra_fields as $extraField): /* RL130301 $evenodd added */ ?> 
                        <?php if($extraField->value != '') { $evenodd++; ?>
                        <li class="<?php echo ($evenodd%2) ? "odd" : "even"; ?> type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?>">
                                <?php if($extraField->type == 'header'): ?>
                                <h4 class="itemExtraFieldsHeader"><?php echo $extraField->name; ?></h4>
                                <?php else: ?>
                                <span class="itemExtraFieldsLabel"><?php echo $extraField->name; ?>:</span>
                                <span class="itemExtraFieldsValue"><?php echo $extraField->value; ?></span>
                                <?php endif; ?>
                        </li>
                        <?php } ?>
                        <?php endforeach; ?>
                </ul>

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum