- Posts: 19
COMMUNITY FORUM
Default Item Image
- Paul
-
Topic Author
- Offline
- New Member
Less
More
10 years 5 months ago #134371
by Paul
Default Item Image was created by Paul
Hi,
Is there a way of setting a default image for all K2 Items that do not have a chosen image?
If the answer is yes, please show me how to do this.
Thanks
Is there a way of setting a default image for all K2 Items that do not have a chosen image?
If the answer is yes, please show me how to do this.
Thanks
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- User
Less
More
10 years 5 months ago #134405
by Krikor Boghossian
Replied by Krikor Boghossian on topic Default Item Image
getk2.org/documentation/tutorials/174-templating-with-k2-and-the-concepts-of-sub-templates
This post will help you with the overrides.
You need to change the item.php's image code to this.
The logic remains the same for the listing templates (category_item.php, tag.php, user.php and generic.php)
This post will help you with the overrides.
You need to change the item.php's image code to this.
<?php if($this->item->params->get('itemImage')):?>
<?php if(!empty($this->item->image)): ?>
<!-- Item Image -->
<div class="itemImageBlock">
<span class="itemImage">
<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;" />
</span>
<div class="clr"></div>
</div>
<?php else: //no K2 image is present ?>
<div class="itemImageBlock">
<span class="itemImage">
<img src="<?php echo JURI::root(); ?>templates/cine/images/placeholder.png" alt="<?php echo K2HelperUtilities::cleanHtml($this->item->title); ?>" style="width:<?php echo $this->item->imageWidth; ?>px; height:auto;" />
</span>
</div>
<?php endif; ?>
<?php endif; ?>
The logic remains the same for the listing templates (category_item.php, tag.php, user.php and generic.php)
Please Log in or Create an account to join the conversation.
- Paul
-
Topic Author
- Offline
- New Member
Less
More
- Posts: 19
10 years 4 months ago #134905
by Paul
Replied by Paul on topic Default Item Image
Which item.php are you talking about? What is the path to it?
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- User
Less
More
10 years 4 months ago #134913
by Krikor Boghossian
Replied by Krikor Boghossian on topic Default Item Image
Please read the post in the link I sent you.
Please Log in or Create an account to join the conversation.
- Jo
-
- User
Less
More
10 years 4 months ago #134968
by Jo
Replied by Jo on topic Default Item Image
Thank you very much!.
Excellent post as I have been trying to get a default image for quite a while. With the templates system you can even have a different default image per template.
There is just one issue.. When I add the code to the category_item.php I lose the link on the image to the article. Could you possible let me know what I would have to change?
Thanks again
Excellent post as I have been trying to get a default image for quite a while. With the templates system you can even have a different default image per template.
There is just one issue.. When I add the code to the category_item.php I lose the link on the image to the article. Could you possible let me know what I would have to change?
Thanks again
Please Log in or Create an account to join the conversation.
- Jo
-
- User
Less
More
10 years 4 months ago #134969
by Jo
Replied by Jo on topic Default Item Image
I got it finally, posting if it help sombody else.
For category_item.php use this code and change the path to your image.
Works for me anyway!
For category_item.php use this code and change the path to your image.
Works for me anyway!
<?php if($this->item->params->get('itemImage')):?>
<?php if(!empty($this->item->image)): ?>
<!-- Item Image -->
<div class="itemImageBlock">
<span class="itemImage">
<a href="<?php echo $this->item->link; ?>"><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>
<div class="clr"></div>
</div>
<?php else: //no K2 image is present ?>
<div class="itemImageBlock">
<span class="itemImage">
<a href="<?php echo $this->item->link; ?>"><img src="<?php echo JURI::root(); ?>templates/default/images/myimage.jpg" alt="<?php echo K2HelperUtilities::cleanHtml($this->item->title); ?>" style="width:<?php echo $this->item->imageWidth; ?>px; height:auto;" /></a>
</span>
</div>
<?php endif; ?>
<?php endif; ?>
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- User
Less
More
10 years 4 months ago #134993
by Krikor Boghossian
Replied by Krikor Boghossian on topic Default Item Image
Thank you for sharing Jo.
Please Log in or Create an account to join the conversation.