Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

Facebook & Twitter Friendly XC 4.5.5

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #1  
Old 08-27-2014, 11:07 AM
  mcanitano's Avatar 
mcanitano mcanitano is offline
 

eXpert
  
Join Date: Feb 2006
Location: Melbourne, FL
Posts: 216
 

Default Facebook & Twitter Friendly XC 4.5.5

Just wanted to share with everyone the custom code we used on our XC 4.5.5 site to integrate Facebook Open Graph and Twitter Cards for mostly every page.

Let us know if you have questions or suggestions!

9-10-2014: Added fix for categories, php pages, static pages, and manufacturer pages. Also cleaned up coding.
10-27-2014: Added compatibility for special offers module pages

Code:
<meta property="fb:admins" content="1099545101" /> <meta property="og:locale" content="en_US" /> <meta property="og:url" content="http://{$smarty.server.HTTP_HOST}{$smarty.server.REQUEST_URI}" /> <meta property="og:site_name" content="{$lng.lbl_site_name|default:$config.Company.company_name|amp}" /> <meta name="twitter:site" content="@silverhorseusa"> <meta name="twitter:creator" content="@silverhorseusa"> <meta name="twitter:title" content="{$meta_title}"> <meta name="twitter:domain" content="http://{$smarty.server.HTTP_HOST}"> {*Add {$smarty.server.REQUEST_URI} to end of content to enable full URL to show *} {if $main eq "product"} {assign var="prod_descr" value=$product.descr|default:$product.fulldescr} <meta property="og:type" content="product" /> <meta property="og:title" content="{$product.product|escape}" /> <meta property="og:description" content="{$prod_descr}" /> <meta property="og:image" content="{$product.image_url}" /> <meta property="product:price:amount" content="{$product.price}" /> <meta property="product:price:currency" content="USD" /> <meta name="twitter:card" content="product"> <meta property="twitter:description" content="{$prod_descr|truncate:'400':'...':false|strip_tags}"> <meta name="twitter:image:src" content="{$product.image_url}"> <meta name="twitter:data1" content="${$product.price}"> <meta name="twitter:label1" content="PRICE"> <meta name="twitter:data2" content="{$product.productcode}"> <meta name="twitter:label2" content="SKU"> {elseif $main eq "catalog" and $cat ne "0"} {assign var="cat_descr" value=$current_category.meta_description} <meta property="og:type" content="website" /> <meta property="og:description" content="{$cat_descr}" /> <meta property="og:title" content="{$meta_title}" /> <meta property="og:image" content="http://{$smarty.server.HTTP_HOST}/{$current_category.image_path}" /> <meta property="og:image:secure_url" content="https://{$smarty.server.HTTP_HOST}/{$current_category.image_path}" /> <meta name="twitter:card" content="summary"> <meta name="twitter:description" content="{$cat_descr}"> <meta name="twitter:image:src" content="http://{$smarty.server.HTTP_HOST}/{$current_category.image_path}"> {elseif $main eq "manufacturer_products"} <meta property="og:type" content="website" /> <meta property="og:description" content="{$manufacturer.meta_description}" /> <meta property="og:title" content="{$meta_title}" /> <meta property="og:image" content="{$manufacturer.image_url}" /> <meta property="og:image:secure_url" content="https://{$smarty.server.HTTP_HOST}/{$manufacturer.image_path}" /> <meta name="twitter:card" content="summary"> <meta name="twitter:description" content="{$manufacturer.meta_description}"> <meta name="twitter:image:src" content="{$manufacturer.image_url}"> {elseif $main eq "customer_offers"} {foreach name=offers from=$offers item=offer} <meta property="og:type" content="website" /> <meta property="og:description" content="{$offer.offer_name}" /> <meta property="og:title" content="{$meta_title}" /> <meta property="og:image" content="{$offer.image_url}" /> <meta name="twitter:card" content="summary"> <meta name="twitter:description" content="{$offer.offer_name}"> <meta name="twitter:image:src" content="{$offer.image_url}"> {/foreach} {else} <meta property="og:type" content="website" /> <meta property="og:description" content="Performance Dodge, Chevy, &amp; Ford Mustang Billet Parts &amp; Accessories" /> <meta property="og:title" content="{$meta_title}" /> <meta property="og:image" content="http://www.silverhorseracing.com/logo-images/SilverHorse%20Racing%20Logo.jpg" /> <meta property="og:image:secure_url" content="https://www.silverhorseracing.com/logo-images/SilverHorse%20Racing%20Logo.jpg" /> <meta name="twitter:card" content="summary"> <meta name="twitter:description" content="Performance Dodge, Chevy, &amp; Ford Mustang Billet Parts &amp; Accessories"> <meta name="twitter:image:src" content="http://www.silverhorseracing.com/logo-images/SilverHorse%20Racing%20Logo.jpg"> {/if}

Note that for
Code:
<meta property="og:title" content="{$meta_title}" /> ... <meta name="twitter:title" content="{$meta_title}">
to work. You must edit /include/templater/plugins/func.get_title.php

AFTER around line 115:
Code:
if (is_string($title)) { $title = str_replace(array("\n", "\r"), array('', ''), trim($title));

AND


AFTER around line 150:
Code:
if (empty($title_items)) $title_items = array($lbl_site_title); ....... $title = str_replace(array("\n", "\r"), array('', ''), trim(implode(' - ', $title_items)));*/

INPUT:
Code:
$smarty->assign('meta_title', $title);

Be sure to add twitter bot to your robots.txt file:
Code:
User-agent: Twitterbot Disallow:
***Note: Not all of this code is ours, we had some help from: http://forum.x-cart.com/showthread.php?t=66474
ALSO: This code becomes a little bit tricky if using CDSEO Pro, as the meta title,descriptions,keywords are all from CDSEO and will have to be assigned to a variable in php. If you'd like to see this work (we have ours working) PM me.
__________________
Marcello Canitano
New Site: X-Cart v4.5.5 GOLD
X-Cart Mobile v1.4.3
X-Payments v1.0.6
CDSEO Pro v2
Total Server Solutions xCDN

www.silverhorseracing.com
Reply With Quote

The following 2 users thank mcanitano for this useful post:
ADDISON (08-29-2014), totaltec (08-27-2014)
  #2  
Old 08-27-2014, 11:13 AM
  totaltec's Avatar 
totaltec totaltec is offline
 

X-Guru
  
Join Date: Jan 2007
Location: Louisville, KY USA
Posts: 5,823
 

Default Re: Facebook & Twitter Friendly XC 4.5.5

Very nice of you to share this. Its a hole in my knowledge, I appreciate it.
__________________
Mike White - Now Accepting new clients and projects! Work with the best, get a US based development team for just $125 an hour. Call 1-502-773-6454, email mike at babymonkeystudios.com, or skype b8bym0nkey

XcartGuru
X-cart Tutorials | X-cart 5 Tutorials

Check out the responsive template for X-cart.
Reply With Quote
  #3  
Old 08-28-2014, 02:59 AM
 
xtech xtech is offline
 

X-Adept
  
Join Date: Jun 2010
Posts: 605
 

Default Re: Facebook & Twitter Friendly XC 4.5.5

Quote:
Originally Posted by mcanitano
Just wanted to share with everyone the custom code we used on our XC 4.5.5 site to integrate Facebook Open Graph and Twitter Cards for mostly every page.

Let us know if you have questions or suggestions!

Code:
{if $main eq "product"} {assign var="prod_descr" value=$product.descr|default:$product.fulldescr} <meta property="og:locale" content="en_US"> <meta property="fb:admins" content="[ADMIN ID]" /> <meta property="og:type" content="website" /> <meta property="og:url" content="http://{$smarty.server.HTTP_HOST}{$smarty.server.REQUEST_URI}"/> <meta property="og:title" content="{$product.product|escape}" /> <meta property="og:description" content="{$product.descr}" /> <meta property="og:image" content="{$product.image_url}" /> <meta property="og:site_name" content="{$lng.lbl_site_name|default:$config.Company.company_name|amp}" /> <meta property="product:price:amount" content="{$product.price}" /> <meta property="product:price:currency" content="USD" /> <meta name="twitter:card" content="product"> <meta name="twitter:site" content="@XXXX"> <meta name="twitter:creator" content="@XXXX"> <meta name="twitter:title" content="{$product.product|escape}"> <meta name="twitter:description" content="{$prod_descr|truncate:'400':'...':false|strip_tags}"> <meta name="twitter:image:src" content="{$product.image_url}"> <meta name="twitter:data1" content="${$product.price}"> <meta name="twitter:label1" content="PRICE"> <meta name="twitter:data2" content="{$product.productcode}"> <meta name="twitter:label2" content="SKU"> <meta name="twitter:domain" content="http://{$smarty.server.HTTP_HOST}{$smarty.server.REQUEST_URI}"> {else} <meta property="og:description" content="[Here we input our custom description]" /> <meta property="og:locale" content="en_US" /> <meta property="fb:admins" content="1099545101" /> <meta property="og:type" content="website" /> <meta property="og:url" content="http://{$smarty.server.HTTP_HOST}{$smarty.server.REQUEST_URI}" /> <meta property="og:title" content="{$meta_title}" /> <meta property="og:image" content="[Here we inserted our company logo]" /> <meta property="og:image:secure_url" content="here we inserted our company logo" /> <meta property="og:site_name" content="{$lng.lbl_site_name|default:$config.Company.company_name|amp}" /> <meta name="twitter:card" content="summary"> <meta name="twitter:site" content="@XXXX"> <meta name="twitter:title" content="{$meta_title}"> <meta name="twitter:description" content="[Here we input our custom description]"> <meta name="twitter:creator" content="@XXXX"> <meta name="twitter:image:src" content="[Here we inserted our company logo]"> <meta name="twitter:domain" content="http://{$smarty.server.HTTP_HOST}"> {/if}

Note that for
Code:
<meta property="og:title" content="{$meta_title}" /> ... <meta name="twitter:title" content="{$meta_title}">
to work. You must edit /include/templater/plugins/func.get_title.php AFTER around line 150:
Code:
if (empty($title_items)) $title_items = array($lbl_site_title); ....... $title = str_replace(array("\n", "\r"), array('', ''), trim(implode(' - ', $title_items)));*/

Input:
Code:
$smarty->assign('meta_title', $title);


***Note: Not all of this code is ours, we had some help from: http://forum.x-cart.com/showthread.php?t=66474

Will it work on 4.6.1 Platinum?
__________________
X-cart Platinum
4.6.1
Reboot template
Reply With Quote
  #4  
Old 09-08-2014, 09:35 AM
  mcanitano's Avatar 
mcanitano mcanitano is offline
 

eXpert
  
Join Date: Feb 2006
Location: Melbourne, FL
Posts: 216
 

Default Re: Facebook & Twitter Friendly XC 4.5.5

Quote:
Originally Posted by xtech
Will it work on 4.6.1 Platinum?

I have not tested it, but I don't see there being any major issues using this on 4.6.1 since it is all meta tags. The only problem you may have is finding the code in /include/templater/plugins/func.get_title.php.
__________________
Marcello Canitano
New Site: X-Cart v4.5.5 GOLD
X-Cart Mobile v1.4.3
X-Payments v1.0.6
CDSEO Pro v2
Total Server Solutions xCDN

www.silverhorseracing.com
Reply With Quote
  #5  
Old 09-08-2014, 12:30 PM
  mcanitano's Avatar 
mcanitano mcanitano is offline
 

eXpert
  
Join Date: Feb 2006
Location: Melbourne, FL
Posts: 216
 

Default Re: Facebook & Twitter Friendly XC 4.5.5

Edited first post. func.get_title.php needs the smarty variable assigned in two sections (was not passing title variable to smarty with static pages, now works)
__________________
Marcello Canitano
New Site: X-Cart v4.5.5 GOLD
X-Cart Mobile v1.4.3
X-Payments v1.0.6
CDSEO Pro v2
Total Server Solutions xCDN

www.silverhorseracing.com
Reply With Quote
  #6  
Old 09-10-2014, 12:15 PM
  mcanitano's Avatar 
mcanitano mcanitano is offline
 

eXpert
  
Join Date: Feb 2006
Location: Melbourne, FL
Posts: 216
 

Default Re: Facebook & Twitter Friendly XC 4.5.5

Edited first post again. The only change here is the coding in smarty tpl.

9-10-2014: Category, php, static, and manufacturer pages now work as they should, and the code has been cleaned up

10-15-2014: Manufacturer page images now work correctly
__________________
Marcello Canitano
New Site: X-Cart v4.5.5 GOLD
X-Cart Mobile v1.4.3
X-Payments v1.0.6
CDSEO Pro v2
Total Server Solutions xCDN

www.silverhorseracing.com
Reply With Quote
  #7  
Old 10-27-2014, 07:01 AM
  mcanitano's Avatar 
mcanitano mcanitano is offline
 

eXpert
  
Join Date: Feb 2006
Location: Melbourne, FL
Posts: 216
 

Default Re: Facebook & Twitter Friendly XC 4.5.5

Added Special Offers compatibility

(i.e. if posting a link like: www.example.com/offers.php?mode=offer&offerid=31)
__________________
Marcello Canitano
New Site: X-Cart v4.5.5 GOLD
X-Cart Mobile v1.4.3
X-Payments v1.0.6
CDSEO Pro v2
Total Server Solutions xCDN

www.silverhorseracing.com
Reply With Quote
  #8  
Old 03-17-2017, 03:34 PM
  christindall's Avatar 
christindall christindall is offline
 

eXpert
  
Join Date: Dec 2007
Location: Everett, WA
Posts: 264
 

Default Re: Facebook & Twitter Friendly XC 4.5.5

Any update on this for 4.7.x branch? With and without CDSEO Pro?
Figured I'd ask before I play with it, as it might save some time.
__________________
Chris Tindall
x-cart 4.7.5 Gold Plus
www.theweedpatchstore.com
AlteredCart: On-Sale, One Page Checkout, Checkout One Payments (although that's not working yet)
BCSE: Back in stock Notify, Checkbox Radio Mod, Upselling Links
SMACK: CDSEO Pro, Product Map
X-Cart: Gold+, Mobile
(still trying to get working: Gahela Support Suite)
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 02:21 PM.

   

 
X-Cart forums © 2001-2020