Keyword

Fixed height for images

  • theant
  • theant's Avatar Topic Author
  • Offline
  • Premium Member
More
11 years 8 months ago #108691 by theant
Fixed height for images was created by theant
Hello
I need to set a fixed height for K2 images instead of the width. Is it possibile?
As you can see into the attached screenshot it should be better a fixed height than the width.
How to?
Attachments:

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

More
11 years 8 months ago #108692 by Matt
Replied by Matt on topic Re: Fixed height for images
It's possible with a core edit. I will explain it how you can do it with images on category pages (catItemImage).

First find components/com_k2/templates/default/category_item.php and copy it in templates/yourTemplate/html/com_k2/templates/default. This is called a template override. With this you can update K2 without losing your core edits.

Then open category_item.php and find
<span class="catItemImage">
		    <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); ?>">
		    	<img src="<?php echo $this->item->image; ?>" alt="<?php if(!empty($this->item->image_caption)) echo K2HelperUtilities::cleanHtml($this->item->image_caption); else echo K2HelperUtilities::cleanHtml($this->item->title); ?>" style="width:<?php echo $this->item->imageWidth; ?>px; height:auto;" />
		    </a>
		  </span>

There you can see this line:
style="width:<?php echo $this->item->imageWidth; ?>px; height:auto;

Change it to:
style="height:<?php echo $this->item->imageWidth; ?>px; width:auto;

From now on, if you set a fixed width for your category images in your ACP, you will instead set a fixed height and a dynamic width.

You need to make these steps also in the item.php (for article images). I think you can figure it out yourself now.

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

  • theant
  • theant's Avatar Topic Author
  • Offline
  • Premium Member
More
11 years 8 months ago - 11 years 8 months ago #108693 by theant
Replied by theant on topic Re: Fixed height for images
Thanks Matt
It works!

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


Powered by Kunena Forum