Keyword

How to add class only into the first child of K2 Content Module's items list

  • Dayyal Dg.
  • Dayyal Dg.'s Avatar Topic Author
  • Offline
  • New Member
More
5 years 2 weeks ago #173560 by Dayyal Dg.
Hello, I am creating a slider powered by Bootstrap 4 and K2 Content Module. It's working fine but the below php code is adding class active into the last child.

<?php echo ($key%2) ? "odd" : "even"; if(count($items)==$key+1) echo ' active'; ?>

I need class active only into the first child. Below is the complete code currently I am using.

<div id="featuredVideo" class="k2-slider-d carousel slide" data-ride="carousel">
<?php if(count($items)): ?>
<ul class="carousel-inner slider-inner" role="listbox" >
<?php foreach ($items as $key=>$item): ?>
<li class="carousel-item wVideo <?php echo ($key%2) ? "odd" : "even"; if(count($items)==$key+1) echo ' active'; ?>">

<?php if($params->get('itemImage') || $params->get('itemTitle')): ?>

<?php if($params->get('itemImage') && isset($item->image)): ?>
<a class="wImg" href="<?php echo $item->link; ?>">
<img src="<?php echo $item->image; ?>" alt="<?php echo K2HelperUtilities::cleanHtml($item->title); ?>" />
<?php if($params->get('itemTitle')): ?>
<span class="wTitle"><?php echo $item->title; ?></span>
<?php endif; ?>

<?php if($params->get('itemVideo') && !empty($item->video)): ?>
<span class="wMedia">
<img src="static.bioscience.com.pk/templates/bspk/images/system/video-play.svg">
</span>
<?php endif; ?>

<?php if($params->get('itemDateCreated')): ?>
<span class="wDate">Published on <?php echo JHTML::_('date', $item->created, 'd F Y'); ?></span>
<?php endif; ?>

</a>
<?php endif; ?>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<a class="carousel-control-prev lt-arrow" href="#featuredVideo" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next rt-arrow" href="#featuredVideo" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
The topic has been locked.
More
5 years 2 weeks ago #173570 by JoomlaWorks
Change this:
if(count($items)==$key+1) echo ' active';

to this:
if($key==0) echo ' active';

Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
The topic has been locked.
  • Dayyal Dg.
  • Dayyal Dg.'s Avatar Topic Author
  • Offline
  • New Member
More
5 years 2 weeks ago #173571 by Dayyal Dg.
Thank you so much, Sir.
The topic has been locked.
More
5 years 2 weeks ago #173572 by JoomlaWorks
You're welcome.

Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
The topic has been locked.

Powered by Kunena Forum