- Posts: 19
COMMUNITY FORUM
k2 Item image default
- Makis Christopoulos
- Topic Author
- Offline
- New Member
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.
- JoomlaWorks
- Away
- Admin
- Posts: 6218
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
- Topic Author
- Offline
- New Member
- Posts: 19
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
- Topic Author
- Offline
- New Member
- Posts: 19
Please Log in or Create an account to join the conversation.
- JoomlaWorks
- Away
- Admin
- Posts: 6218
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
- Topic Author
- Offline
- New Member
- Posts: 19
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.
- JoomlaWorks
- Away
- Admin
- Posts: 6218
Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- JoomlaWorks
- Away
- Admin
- Posts: 6218
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
- Topic Author
- Offline
- New Member
- Posts: 19
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
Please Log in or Create an account to join the conversation.
- Makis Christopoulos
- Topic Author
- Offline
- New Member
- Posts: 19
do you have any new ?
Thanks!!
Please Log in or Create an account to join the conversation.