Friday , December 20 2024

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 admin

Hi there! My name is Iryna, I am a web developer from Ukraine. While working on freelance projects I often face different technical issues and in this blog I publish articles on how to solve them. I am also interested in digital drawing and in this blog you will find brief tutorials that helped me and hopefully can help you as well.

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 *