Keyword

Default Image for K2 Items

  • David Lohan
  • David Lohan's Avatar Topic Author
  • Offline
  • New Member
More
10 years 5 months ago #120109 by David Lohan
Default Image for K2 Items was created by David Lohan
I have been researching this issue and I found some post from a few years ago. Is there anyway to create a pool of default images for items which have no images in them?

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

More
10 years 5 months ago #120110 by JoomlaWorks
Replied by JoomlaWorks on topic Re: Default Image for K2 Items
I think it's easier to create this logic in your template overrides. In pseudo coding:

"If K2 item image doesn't exist, fetch a random image from folder X".

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

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

  • David Lohan
  • David Lohan's Avatar Topic Author
  • Offline
  • New Member
More
10 years 5 months ago #120111 by David Lohan
Replied by David Lohan on topic Re: Default Image for K2 Items
Fotis,

Sincerest thanks for your assistance. I'm not a coder unfortunately. Would you have any idea where I might find some instructions, or an example, to achieve this goal?

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

More
10 years 3 months ago #120112 by zaqaz
Replied by zaqaz on topic Re: Default Image for K2 Items
How to di it in j.3 and K2 2.6?

I'd like to have a deafult imgae in each category (deafult image for items/articles in category) for ex. in category photo ->photo.jpg, for movie -> movie.jpg etc.

Any ideas?
If it's inpossible to do, one deafult image for whole items (articles) will be also goood solution.

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 3 months ago #120113 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: Default Image for K2 Items
You can use this for a staring point
<?php if($this->item->params->get('catItemImage'): ?>
	  <!-- Item Image -->
	  <div class="catItemImageBlock">
		  <span class="catItemImage">
		    <a href="<?php echo $this->item->link; ?>" title="<?php if(!empty($this->item->image_caption)) echo K2HelperUtilities::cleanHtml($this->item->image_caption); else echo K2HelperUtilities::cleanHtml($this->item->title); ?>">
		    	<?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: ?>
		    	INSERT YOUR PLACEHOLDER HERE
		    	<?php endif; ?>
		    </a>
		  </span>
		  <div class="clr"></div>
	  </div>
	  <?php endif; ?>

This is for the category_item.php file. The same logic applies to item.php as well.
I suggest you use overrides. Read this tutorial on template overrides before modifying any code: 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
10 years 3 months ago #120114 by zaqaz
Replied by zaqaz on topic Re: Default Image for K2 Items
Thanks a lot for help, but i am so... how to say it...
How do it works? I suppouse that i have to pase in category_item.php but where exacy? PHP is like chinese for me - looks good, but i do not understood it at all ;)

I have override the k2 like You post, so it;s done.

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

  • Yiota
  • Yiota's Avatar
  • Visitor
10 years 3 months ago #120115 by Yiota
Replied by Yiota on topic Re: Default Image for K2 Items
Hello zaqaz,

Just open the category_item.php file which is located in the overrides you have created

Locate this block of code
<?php if($this->item->params->get('catItemImage'): ?>
         <!-- Item Image -->
         <div class="catItemImageBlock">
           <span class="catItemImage">
                 <a href="<?php echo $this->item->link; ?>" title="<?php if(!empty($this->item->image_caption)) echo K2HelperUtilities::cleanHtml($this->item->image_caption); else echo K2HelperUtilities::cleanHtml($this->item->title); ?>">
                        <?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 endif; ?>
               </a>
              </span>
             <div class="clr"></div>
     </div>
      <?php endif; ?>

and replace it with the one @krikor provided below.

Then right where it says INSERT YOUR PLACEHOLDER HERE just add the <img> element you want to load as your default image.

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


Powered by Kunena Forum