Keyword

Item Image as Facebook sharing thumbnail

  • bkemler
  • bkemler's Avatar Topic Author
  • Offline
  • Premium Member
More
14 years 1 week ago #88605 by bkemler
The site where I use K2 has tons of photos on each page. So I figured out how to make sure that when someone shares one of my K2 Item pages on Facebook, it uses the Item Image as the thumbnail, instead of making the user scroll through a ton of pictures. So I thought I would share the info!Insert this code into /components/com_k2/views/item/view.html.php. I put it in the Metadata section.         if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_XS.jpg')) {            $document->addCustomTag('<link rel="image_src" href="'.JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_XS.jpg"');         }In order for this to work properly, your XS images must meet Facebook's thumbnail size requirements. developers.facebook.com/docs/share"The thumbnail's width AND height must be at least 50 pixels, and cannot exceed 130x110 pixels. The ratio of both height divided by width and
width divided by height (w/h, h/w) cannot exceed 3.0. For example, an
image of 126x39 pixels will not be displayed, as the ratio of width
divided by height is greater than 3.0 (126/39 = 3.23). Images will be
resized proportionally."

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

More
13 years 11 months ago #88606 by kire timov
Replied by kire timov on topic Item Image as Facebook sharing thumbnail
pfff that sux about the image size standards... pfff it SUX.. i really needed that option
thanks for your effort

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

More
13 years 10 months ago #88607 by kire timov
Replied by kire timov on topic Item Image as Facebook sharing thumbnail
i tired adding this just after the //set metadata and it's not working, it still loads all the images

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

  • bkemler
  • bkemler's Avatar Topic Author
  • Offline
  • Premium Member
More
13 years 10 months ago #88608 by bkemler
Replied by bkemler on topic Item Image as Facebook sharing thumbnail
kire timov said:i tired adding this just after the //set metadata and it's not working, it still loads all the images



Hmmm.... it works on my site. www.homewardtrails.org


How good is your level of knowledge of PHP? When you say "just after the //set metadata", you didn't put it on the same line as that and therefore comment it out, did you?

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

More
13 years 10 months ago #88609 by kire timov
Replied by kire timov on topic Item Image as Facebook sharing thumbnail
my php knowledge is low but ofc it was not on the same line .. ^^

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

More
13 years 10 months ago #88610 by kire timov
Replied by kire timov on topic Item Image as Facebook sharing thumbnail
any ideas?

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

  • bkemler
  • bkemler's Avatar Topic Author
  • Offline
  • Premium Member
More
13 years 10 months ago #88611 by bkemler
Replied by bkemler on topic Item Image as Facebook sharing thumbnail
kire timov said:any ideas?



Another thing that's probably obvious but worth checking... you're looking at a page that's an item view, right? This fix doesn't do anything for a page that shows a category view, tag view, etc.

Beyond that, all I can tell you is the process of elimination that I would use. First I would go to a K2 item view and see if the link rel=image_src tag is showing up in the head tag at all. If so, then there must be a problem with what's in the tag if it's not working so you need to mess around with that part of it. If not, then there must be a problem with the if statement or with the addCustomTag so you need to mess around with that... like maybe copying and pasting from the forum messed up a character or something.

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

More
13 years 10 months ago #88612 by kire timov
Replied by kire timov on topic Item Image as Facebook sharing thumbnail
Well actually i am not able to do this- i dont know php :(.. However i may tough of what could be problem.. in item view in my case, i am not displaying the thumbnail picture.. but only in categoryItemView (dose it have to be shown in item view as well?)
note: and yes we are talking about IN itemView


B Kemler said:kire timov said:any ideas?



Another thing that's probably obvious but worth checking... you're looking at a page that's an item view, right? This fix doesn't do anything for a page that shows a category view, tag view, etc.

Beyond that, all I can tell you is the process of elimination that I would use. First I would go to a K2 item view and see if the link rel=image_src tag is showing up in the head tag at all. If so, then there must be a problem with what's in the tag if it's not working so you need to mess around with that part of it. If not, then there must be a problem with the if statement or with the addCustomTag so you need to mess around with that... like maybe copying and pasting from the forum messed up a character or something.

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

  • bkemler
  • bkemler's Avatar Topic Author
  • Offline
  • Premium Member
More
13 years 10 months ago #88613 by bkemler
Replied by bkemler on topic Item Image as Facebook sharing thumbnail
So just to make sure I'm understanding... You're on the item view of a K2 item that HAS an "item image" but the image isn't displayed. No, the fact that it isn't displayed shouldn't affect it. As long as the XS version of the image exists, it should work.

Did you check to see if the head tag of the page contained a link rel=image_src tag? Checking that doesn't require PHP knowledge.

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

More
13 years 8 months ago #88614 by Jimmy P
Replied by Jimmy P on topic Item Image as Facebook sharing thumbnail
Very nice code Kemler, it did exactly what I wanted to do. The only problem is that you forgot a to close the link tag and it was breaking my template. The correct code would be:
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_XS.jpg')) {            $document->addCustomTag('<link rel="image_src" href="'.JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_XS.jpg">');        

} I'm replying only because someone might find it useful in the future

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


Powered by Kunena Forum