K2 -Default Image option

Feel free to talk about everything related to our Joomla Products
Rate this topic: Evaluations: 0, 0.00 on the average.Evaluations: 0, 0.00 on the average.Evaluations: 0, 0.00 on the average.Evaluations: 0, 0.00 on the average.Evaluations: 0, 0.00 on the average.Evaluations: 0, 0.00 on the average.
GK User
Sat Jan 12, 2013 12:20 pm
Hi,

Most of Gavick frmework are related to community or news/publication site and the front end is purly depending on article Images.

So I feel its best to know any over ride method to have a default Image for K2 article if there is no image attached for it. This will make sure that front end looks solid all the time.

Since its general discussion section I have posted here.. I tried to post in K2 form but didn't get much response for it. Hope I find a good expert who can challenge him self in this issue here.

Good luck guys.. If there is any solution found do let me know here in this board this will be really helpful for our community group.

Thanks,
User avatar
Expert Boarder

teitbite
Sun Jan 13, 2013 1:51 am
Hi

This is a very hard question. You are lucky because couple last days I've been dealing with this problem for my client. Images in K2 are being stored and managed in a very complicated way. Mostly based on file name. But what You are looking for is to add a small script which will be checking if article has a main image and put Your own if it has not. Script is really small, but You need to add it in every layout file in /html/com_content

Code: Select all
if(empty($this->item->image)) :
$this->item->image = URL_TO_DEFAULT_IMAGE;
endif;


This is the easiest way of doing it.
User avatar
Moderator

GK User
Sun Jan 13, 2013 5:51 am
hi,

Thanks for the help and time.
To be more specific html/com_content is located under template folder (for community members)

There are 2 com_content folder. do I need to update in both?
Under com_content folder there are many folders article,archive, category, categories, featured, forms

each folders have there own set of files.

Do I need to update all this files ?

Just to clarify myself before making any changes, also it will be helpful for others.


Thanks for the support
User avatar
Expert Boarder

teitbite
Sun Jan 13, 2013 6:02 pm
Hi

Sorry I've made a small mistake. I was thinking about a folder called /html/com_k2 not com_content.

You need to chang it in files where K2 article is displayed as: item.php and category_item.php (there are others but YOu may not be using them on website).
User avatar
Moderator

GK User
Sun Jan 13, 2013 8:41 pm
Hi,

i have pasted the code in the two files but there is no change happened when I try to add a new article without a image.

Can you specify exactly where you placed the code and how you framed the image url.

or can you attach your working file from ur client here so we can have a blueprint to achieve this out.
User avatar
Expert Boarder

teitbite
Mon Jan 14, 2013 8:15 pm
Hi

Please send me an ftp access and I'll check if it's copied to right place.
User avatar
Moderator

GK User
Mon Jan 14, 2013 9:15 pm
Just sent it right now to your mail id.

Thanks for the help.
RR
User avatar
Expert Boarder

teitbite
Tue Jan 15, 2013 2:33 am
Hi

I cannot find an url to Your site anywhere. But it forced me to read Your question again and I realized than You may not be asking about what I'm giving You a solution for :)

I was giving You a way to always have an image in K2 item article, but I believe You need a way to have a default image in NSP module ysed on frontpage to show "small" articles.

Please check this article: https://www.gavick.com/documentation/jo ... pro-gk4-2/ this part especialy:

All thumbnails are stored in a module cache/ catalog. Additionally, if a given article does not have images, default images default.MOD_ID.png from default/ catalog can be loaded, where MOD_ID is an ID of our module, e.g. newsprol.


Try aslo like that: defaultMOD_ID.png - without the dot. I'm not sure if it wasn;t change because of some problems.
User avatar
Moderator

GK User
Tue Jan 15, 2013 7:07 am
thanks for the help. Well I will work out with the module Image the information is really deep into the content. I never found that last time when I was in the page.

thanks for pointing me out.

Apart from that did you had a chance to check my code placement in k2 template files, is it all normal?
It will be good even I have a default image for k2 item article as well.

thanks

ahut.in is my site url...
User avatar
Expert Boarder

teitbite
Wed Jan 16, 2013 1:36 am
Hi

Code was mostly ok. Just lacking apostrhophs around file path. Also it was copied below image code so has no effect at all. Anyway I cannot check if it's working, becuase all article links shows error 404. I think it's because SEF.
User avatar
Moderator

GK User
Wed Jan 16, 2013 1:29 pm
Hi,

Thanks I have some hoe corrected the code for item.php page and now I can see a default image shown up in the item page if no image is attached.

But I copied the same set of code to category_item.php page it dosent show any images in category page.

Can you assest me in this thanks for your support.

item page link:
http://ahut.in/india-news/politics/tesr.html

category page link:
http://ahut.in/india-news/politics.html


Hope this information will be helpful for you.

The corrected code which works fine in item page but not in category page
<?php if(empty($this->item->image)) :
$this->item->image = '../images/sampledata/fruitshop/apple.jpg';
endif; ?>
User avatar
Expert Boarder

teitbite
Fri Jan 18, 2013 12:35 am
Hi

Just checked. The code to replace was under the acctual code to load an image for article. Now is ok.
User avatar
Moderator

GK User
Fri Jan 18, 2013 6:45 am
cool thanks for the help. Its fine now.

Thanks again for the support.
User avatar
Expert Boarder

GK User
Fri Jan 18, 2013 8:10 am
hi,

I was trying with module image. I have placed two images one with defaultnewspro1.png and the other is default.newspro1.png
The module is not picking off image by any mean. I have placed this image under module/mod_newshowprogk4/cache/default/
the same path said in the documentation.

Do let me know if I am wrong in any way. thanks


teitbite wrote:Hi

I cannot find an url to Your site anywhere. But it forced me to read Your question again and I realized than You may not be asking about what I'm giving You a solution for :)

I was giving You a way to always have an image in K2 item article, but I believe You need a way to have a default image in NSP module ysed on frontpage to show "small" articles.

Please check this article: https://www.gavick.com/documentation/jo ... pro-gk4-2/ this part especialy:

All thumbnails are stored in a module cache/ catalog. Additionally, if a given article does not have images, default images default.MOD_ID.png from default/ catalog can be loaded, where MOD_ID is an ID of our module, e.g. newsprol.


Try aslo like that: defaultMOD_ID.png - without the dot. I'm not sure if it wasn;t change because of some problems.
User avatar
Expert Boarder

teitbite
Fri Jan 18, 2013 11:35 am
Hi

I cannot see a module presenting article without image :) Can You lead me to one ? I see links, which are not showing images at all. Maybe this is what You are asking for ? But links layout is not designed to show any.
User avatar
Moderator

GK User
Fri Jan 18, 2013 4:05 pm
Hi,

I have posted a test article. "test1" which will be displayed in newspr01 (module id) module at top left. This module will be the first module in the home page. just bellow top menu left next to politics module)

do check once and let me know so i can remove of test 1 article.


thanks
User avatar
Expert Boarder

teitbite
Sat Jan 19, 2013 5:09 am
Hi

Ok. I get it. The ID of this module is 589 not 1. So a default file name should looks like this: defaultnewspro589.png
User avatar
Moderator

GK User
Sat Jan 19, 2013 5:31 am
hi,

thanks for comming back. I tried change the file name as described bellow but the condition same.
Are you sure its with module id: number ? or the unique module id newspro1 which is located in right basic setting tab.

the documentation says its example similar to basic setting module id

"All thumbnails are stored in a module cache/ catalog. Additionally, if a given article does not have images, default images default.MOD_ID.png from default/ catalog can be loaded, where MOD_ID is an ID of our module, e.g. newsprol."


neither way the image is not picking up. I have cleared caches and cookies stuff on my browser but still no use.


thanks again for keeping up the support.
User avatar
Expert Boarder

teitbite
Sat Jan 19, 2013 11:31 am
Hi

Success! :)

It worked when I disabled automatic id. But I think this should be working with automatic, but probably a name of the file should be default589.png or something like this. Lets not touch it until it's working :)
User avatar
Moderator

GK User
Sat Jan 19, 2013 6:36 pm
cool thanks for the help...

its really supportive and hope this information will be so helpful for other community members who want to achieve the same effect.


Thanks for all the support .
User avatar
Expert Boarder

teitbite
Sun Jan 20, 2013 11:17 am
Hi

I hope it will. It was an interesting case. Till not I believe noone asked for a case when automatic module ID was ON.
User avatar
Moderator

GK User
Mon Jan 21, 2013 9:10 pm
teitbite wrote:Hi

Just checked. The code to replace was under the acctual code to load an image for article. Now is ok.



Hi,

Its regarding the code purely with k2 item and category page image code related issue.

the code works fine and it picks up the default image when there is no item image for k2. Can this action can be avoided if there is any image present in k2 article.

Generally K2 picks up any image in the article as a article image if there is no item image attached in the image tab.

I want the default image to display only when there is no image in the article just to maintain the flow of the data and reduce unwanted default image in the page.

hope things are real clear.

If there is any solution for this it will be really helpful thanks.
User avatar
Expert Boarder

teitbite
Wed Jan 23, 2013 1:23 am
Hi

I have something better :) I've developed this to use an article image when there is no main image.

Code: Select all
   <?php
      // Extracting image from content if not set
      if(empty($this->item->image)) :
         if(empty($this->item->fulltext)) :
            if(preg_match('/\<img.*src=.*?\>/',$this->item->introtext)) :
               $imgStartPos = JString::strpos($this->item->introtext, 'src="');
               if($imgStartPos)  $imgEndPos = JString::strpos($this->item->introtext, '"', $imgStartPos + 5);   
               if($imgStartPos > 0) $this->item->image = JString::substr($this->item->introtext, ($imgStartPos + 5), ($imgEndPos - ($imgStartPos + 5)));
               $this->item->introtext = str_replace( $this->item->image, 'images/blank.gif" style="display:none;', $this->item->introtext );
            endif;
         else :
            if(preg_match('/\<img.*src=.*?\>/',$this->item->fulltext)) :
               $imgStartPos = JString::strpos($this->item->fulltext, 'src="');
               if($imgStartPos)  $imgEndPos = JString::strpos($this->item->fulltext, '"', $imgStartPos + 5);   
               if($imgStartPos > 0) $this->item->image = JString::substr($this->item->fulltext, ($imgStartPos + 5), ($imgEndPos - ($imgStartPos + 5)));
               $this->item->fulltext = str_replace( $this->item->image, 'images/blank.gif" style="display:none;', $this->item->fulltext );
            endif;
         endif;

      endif;
   ?>
User avatar
Moderator


cron