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
1 week 19 hours ago #173560 by Dayyal Dg.
Dayyal Dg. created the topic: How to add class only into the first child of K2 Content Module's items list
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>

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

  • Fotis
  • Fotis's Avatar
  • Offline
  • Administrator
  • JoomlaWorks Support Team
More
6 days 22 hours ago #173570 by Fotis
Fotis replied the topic: How to add class only into the first child of K2 Content Module's items list
Change this:
if(count($items)==$key+1) echo ' active';

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

If you use & love K2, please take a moment to add your review and rate it
at the Joomla Extensions Directory: extensions.joomla.org/extension/k2/


IMPORTANT: Please search the forum before posting a question!

JoomlaWorks Support Team Member

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

  • Dayyal Dg.
  • Dayyal Dg.'s Avatar Topic Author
  • Offline
  • New Member
More
6 days 21 hours ago #173571 by Dayyal Dg.
Dayyal Dg. replied the topic: How to add class only into the first child of K2 Content Module's items list
Thank you so much, Sir.

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

  • Fotis
  • Fotis's Avatar
  • Offline
  • Administrator
  • JoomlaWorks Support Team
More
6 days 18 hours ago #173572 by Fotis
Fotis replied the topic: How to add class only into the first child of K2 Content Module's items list
You're welcome.

If you use & love K2, please take a moment to add your review and rate it
at the Joomla Extensions Directory: extensions.joomla.org/extension/k2/


IMPORTANT: Please search the forum before posting a question!

JoomlaWorks Support Team Member

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


Powered by Kunena Forum