Keyword

k2 Item image default

  • Makis Christopoulos
  • Makis Christopoulos's Avatar Topic Author
  • Offline
  • New Member
More
5 years 10 months ago #172405 by Makis Christopoulos
k2 Item image default was created by Makis Christopoulos
hello.
I am young here, but no matter what I was looking for, I did not find anything relevant to my question ...
What I want to ask is that.....
Can and how (if i can) set an image as default, so when there is no image in an item, to display the default?

Thanks

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

More
5 years 10 months ago #172406 by JoomlaWorks
Replied by JoomlaWorks on topic k2 Item image default
It's fairly simple actually, but it does require that your create K2 template overrides so you don't lose your changes when you upgrade K2. More info on K2 overrides here: getk2.org/documentation/tutorials/174-templating-with-k2-and-the-concepts-of-sub-templates

Now, if you wanted to show a default image in the item view (in item.php) you could add this at the very top of the file:
<?php

// place the following after the "defined('_JEXEC') or die;" line
if (empty($this->item->image)) {
    $this->item->image = '/path/to/placeholder.jpg';
}

The above code will set a placeholder image when no K2 item image exists. You can follow the same pattern to set a placeholder for category views, modules etc.

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

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

  • Makis Christopoulos
  • Makis Christopoulos's Avatar Topic Author
  • Offline
  • New Member
More
5 years 10 months ago #172407 by Makis Christopoulos
Replied by Makis Christopoulos on topic k2 Item image default

Fotis wrote: It's fairly simple actually, but it does require that your create K2 template overrides so you don't lose your changes when you upgrade K2. More info on K2 overrides here: getk2.org/documentation/tutorials/174-templating-with-k2-and-the-concepts-of-sub-templates

Now, if you wanted to show a default image in the item view (in item.php) you could add this at the very top of the file:

<?php

// place the following after the "defined('_JEXEC') or die;" line
if (empty($this->item->image)) {
    $this->item->image = '/path/to/placeholder.jpg';
}

The above code will set a placeholder image when no K2 item image exists. You can follow the same pattern to set a placeholder for category views, modules etc.


Hello Fotis , and thanks for the quick help. One more thing....can you give me the path for the item.php ?
And yes ....the override is the only way!!
Thanks again!!

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

  • Makis Christopoulos
  • Makis Christopoulos's Avatar Topic Author
  • Offline
  • New Member
More
5 years 10 months ago #172408 by Makis Christopoulos
Replied by Makis Christopoulos on topic k2 Item image default
Ok i found it....Thanks one more time!!!

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

More
5 years 10 months ago #172409 by JoomlaWorks
Replied by JoomlaWorks on topic k2 Item image default
You're welcome :)

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

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

  • Makis Christopoulos
  • Makis Christopoulos's Avatar Topic Author
  • Offline
  • New Member
More
5 years 10 months ago #172410 by Makis Christopoulos
Replied by Makis Christopoulos on topic k2 Item image default
Problem....
I have do it all , but the image not showing....
appear the message "the image could not be loaded"
any idea?

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

More
5 years 10 months ago #172411 by JoomlaWorks
Replied by JoomlaWorks on topic k2 Item image default
What did you use exactly? What's the code you added e.g. in item.php?

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

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

More
5 years 10 months ago #172412 by JoomlaWorks
Replied by JoomlaWorks on topic k2 Item image default
An actual URL would also help...

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

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

  • Makis Christopoulos
  • Makis Christopoulos's Avatar Topic Author
  • Offline
  • New Member
More
5 years 10 months ago - 5 years 10 months ago #172413 by Makis Christopoulos
Replied by Makis Christopoulos on topic k2 Item image default

Fotis wrote: An actual URL would also help...


This is the code :

<?php
if (empty($this->item->image)) {
$this->item->image = '/demo/images/Featured_articles/logo_panaxaikis_gia_site.png';
}
?>

and the url :

www.flyingdads.gr/demo/index.php/item/391-sthn-ispana-shmera-o-sakhs-kalogeropoylos-gia-diapragmateyseis-paiktwn
Last edit: 5 years 10 months ago by Makis Christopoulos.

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

  • Makis Christopoulos
  • Makis Christopoulos's Avatar Topic Author
  • Offline
  • New Member
More
5 years 10 months ago #172414 by Makis Christopoulos
Replied by Makis Christopoulos on topic k2 Item image default
good morning...
do you have any new ?

Thanks!!

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

More
5 years 10 months ago #172415 by JoomlaWorks
Replied by JoomlaWorks on topic k2 Item image default
First off, the image you reference is wrong - "www.flyingdads.gr/demo/images/Featured_articles/logo_panaxaikis_gia_site.png" throws a 404 error.

Secondly, you need to make sure the format is correct - see how it's entered: jmp.sh/21xSJNU

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

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

  • Makis Christopoulos
  • Makis Christopoulos's Avatar Topic Author
  • Offline
  • New Member
More
5 years 10 months ago #172416 by Makis Christopoulos
Replied by Makis Christopoulos on topic k2 Item image default

Fotis wrote: First off, the image you reference is wrong - "www.flyingdads.gr/demo/images/Featured_articles/logo_panaxaikis_gia_site.png" throws a 404 error.

Secondly, you need to make sure the format is correct - see how it's entered: jmp.sh/21xSJNU


Fotis ,
i have fix the wrong image path , and also the format. Now it works like a charm.
Thank you !!!

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

More
5 years 10 months ago #172417 by JoomlaWorks
Replied by JoomlaWorks on topic k2 Item image default
Great :)

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

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

  • Makis Christopoulos
  • Makis Christopoulos's Avatar Topic Author
  • Offline
  • New Member
More
5 years 9 months ago #172550 by Makis Christopoulos
Replied by Makis Christopoulos on topic k2 Item image default
I have one more question ... How do I define a different default mage in a different category, so when there is no photo in an item getting the default from the category? How can it be?

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

More
5 years 9 months ago #172596 by JoomlaWorks
Replied by JoomlaWorks on topic k2 Item image default
You should be able to grab the category ID or name using $this->item->category->id or $this->item->category->name respectively, so get that, check the ID or name (whichever you want to use as differentiator) and then make an if/else statement to load a different default image.

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

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

  • Makis Christopoulos
  • Makis Christopoulos's Avatar Topic Author
  • Offline
  • New Member
More
5 years 9 months ago #172631 by Makis Christopoulos
Replied by Makis Christopoulos on topic k2 Item image default

Fotis wrote: You should be able to grab the category ID or name using $this->item->category->id or $this->item->category->name respectively, so get that, check the ID or name (whichever you want to use as differentiator) and then make an if/else statement to load a different default image.


Hello Fotis and Thank you for your help.
Can you syntax an example please.... Because I am newbie in this?

Thank you very much!!

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

More
5 years 9 months ago #172637 by JoomlaWorks
Replied by JoomlaWorks on topic k2 Item image default
I've given you direction.

If you're going beyond "point & click" tasks in Joomla, you'll need to grasp the basics of PHP.

Providing constant code examples is out of the scope of the support offered here.

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

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

  • Makis Christopoulos
  • Makis Christopoulos's Avatar Topic Author
  • Offline
  • New Member
More
5 years 9 months ago #172643 by Makis Christopoulos
Replied by Makis Christopoulos on topic k2 Item image default
Ok. I understand!!
Thanks

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

  • Makis Christopoulos
  • Makis Christopoulos's Avatar Topic Author
  • Offline
  • New Member
More
5 years 8 months ago #172676 by Makis Christopoulos
Replied by Makis Christopoulos on topic k2 Item image default
Ok
I fix it!!

Thank you!!

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

More
5 years 8 months ago #172679 by JoomlaWorks
Replied by JoomlaWorks on topic k2 Item image default
Great :)

Fotis / 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