Keyword

Default image for K2 Item

  • Startprogram
  • Startprogram's Avatar Topic Author
  • Offline
  • New Member
More
4 years 8 months ago #143880 by Startprogram
Startprogram created the topic: Default image for K2 Item
Is it possible to display a default image in an K2 Item when a user has not attached an image to the Item?

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

More
4 years 8 months ago - 4 years 8 months ago #143886 by Joe Campbell
Joe Campbell replied the topic: Default image for K2 Item
Hi Startprogram,

Based on the default K2 2.6.8 template...

Find:
<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;" />

Replace with:
<?php if(!empty($this->item->image)): ?>    

<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;" />

<?php else: ?>

<img src="http://placehold.it/700x350" 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;" />

<?php endif; ?>

REMINDER:
- Change the placeholder image ( placehold.it/700x350 ) with your desired image

I hope this helps,

Joe Campbell
Last edit: 4 years 8 months ago by Joe Campbell.

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

More
4 years 8 months ago #143899 by Krikor Boghossian
Krikor Boghossian replied the topic: Default image for K2 Item
As always remember to override the template instead of directly editing the core files.

getk2.org/documentation/tutorials/174-templating-with-k2-and-the-concepts-of-sub-templates

IMPORTANT: Please search the forum before posting a question!

JoomlaWorks Support Team Member

---
JoomlaWorks
www.joomlaworks.net/

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

More
4 years 6 months ago #145093 by Mustafa Basaran
Mustafa Basaran replied the topic: Default image for K2 Item
hello it doesnt´go for me.

no default image shown (when no image) in
- item view and
- category view

i replaced in "category_item.php" and "item.php"

can anyone help ?

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

More
4 years 6 months ago #145094 by Joe Campbell
Joe Campbell replied the topic: Default image for K2 Item
Hello Mustafa,

It worked for me - I tested it before posting it. You could always try using NoNumber ReReplacer - www.nonumber.nl/extensions/rereplacer

Use it to perform a Find & Replace of your images.

I hope this helps,

Joe Campbell

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

More
4 years 6 months ago #145101 by Krikor Boghossian
Krikor Boghossian replied the topic: Default image for K2 Item
Read this post -> getk2.org/documentation/tutorials/174-templating-with-k2-and-the-concepts-of-sub-templates in order to locate the files you need to edit.

IMPORTANT: Please search the forum before posting a question!

JoomlaWorks Support Team Member

---
JoomlaWorks
www.joomlaworks.net/

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

More
4 years 5 months ago #146143 by John Farouk
John Farouk replied the topic: Default image for K2 Item
I am very upset and need help I am using K2 in a news website the article main image doesnt appear, I tried everything possible for 5 days now but nothing happened please check URL below it's a K2 Item page you can see the article but no image, please I need help, It's an arabic website so the link is too long sorry for that..


ahlyafrica.com/index.php/bonus-pages/item/238-%D8%A7%D9%84%D8%A3%D9%87%D9%84%D9%8A-%D9%8A%D8%B1%D9%81%D8%B6-%D8%A7%D9%84%D8%B1%D8%A7%D8%AD%D9%87-%D9%82%D8%A8%D9%84-%D9%85%D9%88%D8%A7%D8%AC%D9%87%D8%A9-%D8%B3%D9%85%D9%88%D8%AD%D9%87

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

More
4 years 5 months ago #146171 by Lefteris
Lefteris replied the topic: Default image for K2 Item
@John Farouk

The link you provided is not working. I get a 404 error.

IMPORTANT: Please search the forum before posting a question!

JoomlaWorks Support Team Member

---
JoomlaWorks
www.joomlaworks.net/

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


Powered by Kunena Forum