Monday , February 3 2025

Display video instead of preview in K2 Joomla category

The task is to display a video instead of a preview of the K2 material in the general output of materials in the category.

here wrote about how to display a video from YouTube instead of a picture of the K2 material inside the material.

To display images in categories, use the code:

<?php if($this->item->params->get('catItemImage') && !empty($this->item->image)): ?>
	  <!-- Item Image -->	  
		 
		    <a href="<?php echo $this->item->link; ?>" title="<?php if(!empty($this->item->image_caption)) echo K2HelperUtilities::cleanHtml($this->item->image_caption); else echo K2HelperUtilities::cleanHtml($this->item->title); ?>" style="background-image: url(<?php echo $this->item->image; ?>);" class="item-image-link">		    	
		    </a>		  
	  
	  <?php endif; ?>

Following the example Display video instead of preview in K2 Joomla material, the videolink field has already been created and filled with a link from YouTube.

Then edit the category_item.php file and edit the above code like this:

<?php if(isset($this->item->extraFields->videolink->value) === true  && empty($this->item->extraFields->videolink->value) === false): ?>
<!--<span class="itemExtraFieldsLabel"><?php echo $this->item->extraFields->videolink->name; ?></span>-->
<div class="itemExtraFieldsValue">

<iframe width="350" height="197" src="<?php echo $this->item->extraFields->videolink->value; ?>" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

	</div>

<?php else: ?>

/*here is the code with the output of the picture, published at the beginning of the post*/

	  <?php endif; ?>

About iryna

I'm Iryna, a web developer from Ukraine with a decade of experience solving complex technical challenges in the world of freelance. Throughout my career, I've worked on everything from troubleshooting server-side issues and optimizing website performance to enhancing user interfaces. On this blog, I share detailed solutions to the technical problems I’ve encountered and methods that have worked best for me. In addition to my technical expertise, I’m also passionate about digital drawing. I hope the tutorials and insights I provide here will help both fellow developers and creatives alike in their own projects.

Check Also

How to get a link in an email where the form is filled out via Chronoforms

This task is very simple, for normal CMS. For Joomla, I publish the solution in …

Leave a Reply

Your email address will not be published. Required fields are marked *