If this is your first visit, check our documentation. To post, register or login.
Forums / Templates, Stylesheets, Page Layout / adding product specific info into <head> tags on product pages for facebook

adding product specific info into <head> tags on product pages for facebook

Locked

Started by donplay on 27 Nov 2009, 9:57 PM · Views: 5,571

Results 1 to 10 of 10
This thread is locked. New replies are disabled.
27 Nov 2009, 9:57 PM
#1
donplay avatar

donplay

New Zenner

Join Date:
Jun 2007
Posts:
72
Plugin Contributions:
0

adding product specific info into <head> tags on product pages for facebook

Hi,

I'm trying to add product specific code into my <head> tag so thumbnails show up when product pages are are shared on facebook. Based on following the instructions from facebook (http://wiki.developers.facebook.com/index.php/Connect/Implementing_Facebook_Share#Basic_Markup_for_Description_and_Thumbnails) and this related thread (
http://www.zen-cart.com/forum/showthread.php?t=137585
) I'm trying to add the following code to the page /includes/templates/gargyle/common/html_header.php but the URL gets chopped off before the product name.

<link rel="image_src" href="<?php echo "http://" . $_SERVER['HTTP_HOST'] . "/shop/" . $products_image_medium; ?>"/>

I guess that page doesn't know what $products_image_medium is. Does someone know how I need to edit html_header.php so that the $products_image_medium value can be populated in the header correctly, and that line will show up ONLY for product pages?

Appreciate any help...

thanks,
Don

28 Nov 2009, 7:10 AM
#2
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,512
Plugin Contributions:
176

Re: adding product specific info into <head> tags on product pages for facebook

It's actually pretty simple.

Put your html_header.php file back to how it was before you started trying this.

Then create the following file with the following content:
/includes/modules/pages/product_info/jscript_fbimage.php

<?php
  /**
   * Add "image_src" link to <head> section for current product's image
   */
  $sql = "select p.products_id, p.products_image
           from   " . TABLE_PRODUCTS . " p
           where  p.products_status = '1'
           and    p.products_id = '" . (int)$_GET['products_id'] . "'";
  $product_info = $db->Execute($sql);

  $products_image = $product_info->fields['products_image'];
  if ($products_image == '' and PRODUCTS_IMAGE_NO_IMAGE_STATUS == '1') {
    $products_image = PRODUCTS_IMAGE_NO_IMAGE;
  }
  if ($products_image != '') {
    require(DIR_WS_MODULES . zen_get_module_directory(FILENAME_MAIN_PRODUCT_IMAGE));
?>
<link rel="image_src" href="<?php echo HTTP_SERVER . DIR_WS_CATALOG . $products_image_medium; ?>" />
<?php  }
```That's it!

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

28 Nov 2009, 10:06 PM
#3
donplay avatar

donplay

New Zenner

Join Date:
Jun 2007
Posts:
72
Plugin Contributions:
0

Re: adding product specific info into <head> tags on product pages for facebook

Hi DrByte,

Thanks for your feedback. I tried creating that file on my test server but the "image_src" code isn't showing up on the product page (link here). I'm not sure if I'm getting conflicts with another module I have installed...maybe CSS - Javascript loader (CJ Loader).

wiki.rubikintegration.com/zencart/modules/css_javascript_loader/about

Aside from that I'm not sure what might be wrong...I cut and pasted from your post and created the file as directed but no luck with the code in the <head> tag.

Appreciate any thoughts you might have.

thanks,
Don

28 Nov 2009, 10:27 PM
#4
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,512
Plugin Contributions:
176

Re: adding product specific info into <head> tags on product pages for facebook

donplay:

I tried creating that file on my test server but the "image_src" code isn't showing up on the product page (link here).Well, the code I posted was a copy-and-paste from after I actually tested it to confirm that it did as intended.
Granted, I didn't test it on a site that has been as heavily modified as yours, including so-called "SEO" URLs etc.
donplay:

I'm not sure if I'm getting conflicts with another module I have installed...maybe CSS - Javascript loader (CJ Loader).

wiki.rubikintegration.com/zencart/modules/css_javascript_loader/about
Maybe. Ask them about that.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

28 Nov 2009, 11:23 PM
#5
donplay avatar

donplay

New Zenner

Join Date:
Jun 2007
Posts:
72
Plugin Contributions:
0

Re: adding product specific info into <head> tags on product pages for facebook

Hi DrByte,

Thanks for the reply...understood. I turned off the SSU (SEO) module and the issue was still there. I'll keep digging...thanks for your help.

-Don

5 Dec 2009, 5:23 PM
#6
issy avatar

issy

New Zenner

Join Date:
Jan 2006
Posts:
59
Plugin Contributions:
0

Re: adding product specific info into <head> tags on product pages for facebook

This is what I did on my site, it's the medium size images and they look good on my facebook profile.

1- I pasted the following code before </head> on my html_header.php and saved.

<script> function fbs_click() { u=location.href; t=document.title; window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),' sharer', 'toolbar=0, status=0, width=626, height=436'); return false; } </script>

2- I pasted the following code after <!--eof Product description --> on my tpl_product_info_display.php and saved.

<!--bof facebook share --> <link rel="image_src" href="<?php echo "http://" . $_SERVER['HTTP_HOST'] . "/" . $products_image_medium; ?>"/> <script>function fbs_click() {u=location.href;t=document.title;window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');return false;}</script><style> html .fb_share_link { padding:2px 0 0 20px; height:16px; background:url(<http://b.static.ak.fbcdn.net/rsrc.php/zAB5S/hash/4273uaqa.gif>) no-repeat top left; }</style><a href="http://www.facebook.com/share.php?u=<?php echo "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING'];?>" onclick="return fbs_click()" target="_blank" class="fb_share_link">Share <strong><?php echo $products_name; ?></strong> on Facebook</a> <br class="clearBoth" /> <!--eof facebook share -->

3- Uploaded files to server and it worked out of the box for me, this is on a live site!! :).

Hope that helps some one.

Happy coding...

18 Dec 2009, 7:54 AM
#7
ngeorg22 avatar

ngeorg22

New Zenner

Join Date:
May 2008
Posts:
2
Plugin Contributions:
0

Re: adding product specific info into <head> tags on product pages for facebook

Thank you for the valuable info. I did all this and was able to share my products on my facebook page. My main problem though is that product images do no appear in facebook. Am I missing something?

18 Dec 2009, 8:07 AM
#8
ngeorg22 avatar

ngeorg22

New Zenner

Join Date:
May 2008
Posts:
2
Plugin Contributions:
0

Re: adding product specific info into <head> tags on product pages for facebook

For some curious reason I tried your suggestion second. And it worked for me. Thank you so much!

13 Jan 2010, 10:05 PM
#9
pointsilver avatar

pointsilver

New Zenner

Join Date:
Sep 2008
Posts:
2
Plugin Contributions:
0

Re: adding product specific info into <head> tags on product pages for facebook

This works... some of the code is invalid, but no big deal... something about ampersands etc. > issy:

This is what I did on my site, it's the medium size images and they look good on my facebook profile.

1- I pasted the following code before </head> on my html_header.php and saved.

<script> function fbs_click() { u=location.href; t=document.title; window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),' sharer', 'toolbar=0, status=0, width=626, height=436'); return false; } </script>

2- I pasted the following code after <!--eof Product description --> on my tpl_product_info_display.php and saved.

<!--bof facebook share --> <link rel="image_src" href="<?php echo "http://" . $_SERVER['HTTP_HOST'] . "/" . $products_image_medium; ?>"/> <script>function fbs_click() {u=location.href;t=document.title;window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');return false;}</script><style> html .fb_share_link { padding:2px 0 0 20px; height:16px; background:url(<http://b.static.ak.fbcdn.net/rsrc.php/zAB5S/hash/4273uaqa.gif>) no-repeat top left; }</style><a href="http://www.facebook.com/share.php?u=<?php echo "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING'];?>" onclick="return fbs_click()" target="_blank" class="fb_share_link">Share <strong><?php echo $products_name; ?></strong> on Facebook</a> <br class="clearBoth" /> <!--eof facebook share -->

3- Uploaded files to server and it worked out of the box for me, this is on a live site!! :).

Hope that helps some one.

Happy coding...

17 Feb 2010, 12:34 PM
#10
khopek avatar

khopek

Totally Zenned

Join Date:
Aug 2006
Location:
portlandish, oregon
Posts:
795
Plugin Contributions:
0

Re: adding product specific info into <head> tags on product pages for facebook

Hmmm, now the question is...Is there a solution for addThis, to get it to send the product image url to Facebook? I'm using addThis for all my bookmarking and it is currently just grabbing images from my left column!

@pointsilver, validation errors regarding ampersands simply mean that you have '&' in the code that should be converted to '&' :D