Keyword

K2 related item images link?

More
8 years 5 months ago #149339 by dean
K2 related item images link? was created by dean
Hey everybody

So I made my "related items" to show images and improved its design nice and beautiful. The only thing that bothers me is that by default the images of the related articles do not have links (only the Title etc... the texts) and that's kinda sh*tty since everywhere on my website the images are clickable links (that lead to an article). Not to mention that in mobile it's even more important...

So yeah, I've been searching Google for an answer but with no luck so far.

Screenshot:
i.imgur.com/YVo0JT8.png

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 5 months ago #149351 by Krikor Boghossian
Replied by Krikor Boghossian on topic K2 related item images link?
Here you go:
<?php if($this->params->get('itemRelatedImageSize') && $item->image): ?>
				<a href="<?php echo $item->link ?>">
					<img style="width:<?php echo $item->image->width; ?>px;height:auto;" class="itemRelImg" src="<?php echo $item->image->src; ?>" alt="<?php echo $item->image->alt; ?>" />
				</a>
				<?php endif; ?>

Replace the default code in the item.php file.
Make sure that you are using overrides instead of editing core files:
getk2.org/documentation/tutorials/174-templating-with-k2-and-the-concepts-of-sub-templates

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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

More
8 years 5 months ago #149366 by dean
Replied by dean on topic K2 related item images link?
A simple <a> tag. Who would have guessed :)

Thank you!

By the way I was experiencing problems with your code (the images didn't show up) but I got the general idea.

Here is what worked for me:
	<?php if($this->item->params->get('itemRelatedImageSize')): ?>
            <a href="<?php echo $item->link ?>">
					<img style="width:<?php echo $item->imageWidth; ?>px;height:auto;" class="itemRelImg" src="<?php echo $item->image; ?>" alt="<?php K2HelperUtilities::cleanHtml($item->title); ?>" />
			</a>
	   <?php endif; ?>

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 5 months ago #149374 by Krikor Boghossian
Replied by Krikor Boghossian on topic K2 related item images link?
Good to know I could help :)

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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


Powered by Kunena Forum