Social Media Buttons

Pinterest Images Missing?

This mod is developed for versions 2.82 or higher. If you are using an earlier release, you will need to upgrade to the latest SiteBuilder release to use the mod. The Pinterest mod utilizes the variable $display_sm_image1, which is only available in version 2.82 and higher.

If you'd like to add social media buttons to your products, follow the steps below for version 2.82 systems or higher

UPDATED 6/23/15: For better 2.84 support. See steps 4-5 below.

UPDATED 5/11/2015: Added additional Open Graph tags. See steps 5-7 below.

UPDATED 3/5/14: Formatted buttons (& removed bubbles) and added Google+

UPDATED 1/3/14: Added Facebook meta data tags for optimal image use. See steps 5-7 below.

  1. Add the following script to your template, just above the tag:

    
    
    
    
    
    
    
    
  2. Open the products_variables.php flie in the /enc/ folder, and add the code:

    if (!function_exists("var_pinterest"))
    {
    function var_pinterest($product_name, $product_url, $img_url)
    {
    $pinterest_code="
    Pinterest
    "; return $pinterest_code; } } if (!function_exists("var_facebook")) { function var_facebook($product_url) { $facebook_code="
    "; return $facebook_code; } } if (!function_exists("var_twitter")) { function var_twitter($product_name, $product_url) { $twitter_code=""; return $twitter_code; } } if (!function_exists("var_googleplus")) { function var_googleplus($product_url) { $google_plus="
    "; return $google_plus; } }

    just above the closing PHP tag at the bottom of the page:

    ?>
  3. Open the products_detail.php, products_single.php and products_multisingle.php files in the /enc/ folder, and add the code:

    $display_pinterest = var_pinterest($stripitem, $multitemlink, $display_sm_image1);
    $display_facebook = var_facebook($multitemlink);
    $display_twitter = var_twitter($stripitem, $multitemlink);
    $display_google = var_googleplus($multitemlink);

    Just under the line:

    $display_outofstock = var_overrideoos($searchrow[Inventory], $display_outofstock);
  4. Add the social media variables ($display_pinterest, $display_facebook, $display_twitter, $display_google) to the product layout files (products_detail.php and products_single.php - and products_multisingle.php in versions 2.83 or lower).

    e.g.) If you want to add all social media buttons just under the product, in the /enc/products_details.php, /enc/products_multisingle.php file and the /enc/products_single.php file, add the code:

    echo "";

    just after the line:

    echo "";

    and then in your template's styles, add CSS to stylize those buttons and the surrounding container:

    .socialmedia { text-align: center; margin: auto; padding: 20px 0; }
    .socialmedia>div.insocial { display: inline-block; min-width: 50px; text-align: center; margin: auto; }
  5. Facebook's Open Graph tags will support Pinterest Rich Pins. Please note that only the base item price - the regular price or the sale price - will be used. The option prices or discounts will not be included in the price amount.

    For Open Graph Tags: Open the openinfo.php file in the /enc/ folder, and:

    Version 2.83 or lower:

    $metaquery = "SELECT Keywords, Description, MetaTitle, Item FROM " .SB_DB_PREFIX ."_items WHERE ID='$item'";
    $metaresult = mysql_query($metaquery, $dblink) or die ("Unable to select item. Try again later.");
    $metanum = mysql_num_rows($metaresult);
    if ($metanum == 1)
    {
    $metarow = mysql_fetch_array($metaresult);
    if ($metarow[Keywords])
    $Meta_Keywords=$metarow[Keywords];
    if ($metarow[Description])
    $Meta_Description=$metarow[Description];
    if ($metarow[MetaTitle])
    $Meta_Title=$metarow[MetaTitle];
    else
    $Meta_Title=$metarow[Item];
    $pagetitle = stripslashes($metarow[Item]);

    Change this code to:

    $metaquery = "SELECT Keywords, Description, MetaTitle, Item, SmImage, LgImage, RegPrice, SalePrice FROM " .SB_DB_PREFIX ."_items WHERE ID='$item'";
    $metaresult = mysql_query($metaquery, $dblink) or die ("Unable to select item. Try again later.");
    $metanum = mysql_num_rows($metaresult);
    if ($metanum == 1)
    {
    $metarow = mysql_fetch_array($metaresult);
    if ($metarow[Keywords])
    $Meta_Keywords=$metarow[Keywords];
    if ($metarow[Description])
    $Meta_Description=$metarow[Description];
    if ($metarow[MetaTitle])
    $Meta_Title=$metarow[MetaTitle];
    else
    $Meta_Title=$metarow[Item];
    $pagetitle = stripslashes($metarow[Item]);
    // ADDED FOR OPEN GRAPH TAGS
    if(!empty($metarow[LgImage]))
    $pageimg=imgpathtourl($metarow[LgImage]);
    else if(!empty($metarow[SmImage]))
    $pageimg=imgpathtourl($metarow[SmImage]);
    if ($metarow[SalePrice] > 0)
    $pin_price = $metarow[SalePrice];
    else
    $pin_price = $metarow[RegPrice];
    // END OPEN GRAPH TAGS

    Version 2.84:

    $metaquery = "SELECT Keywords, Description, MetaTitle, Item, Catalog FROM " .SB_DB_PREFIX ."_items WHERE ID='$item'";
    $metaresult = mysql_query($metaquery, $dblink) or die ("Unable to select item. Try again later.");
    $metanum = mysql_num_rows($metaresult);
    if ($metanum == 1)
    {
    $metarow = mysql_fetch_array($metaresult);
    if ($metarow[Keywords])
    $Meta_Keywords=$metarow[Keywords];
    if ($metarow[Description])
    $Meta_Description=$metarow[Description];
    if ($metarow[MetaTitle])
    $Meta_Title=$metarow[MetaTitle];
    else
    $Meta_Title=$metarow[Item];
    $pagetitle = stripslashes($metarow[Item]);
    $catalog_number = (!empty($metarow[Catalog])) ? '#' . stripslashes($metarow[Catalog]) . ' ' : '';
    }

    Change this code to:

    $metaquery = "SELECT Keywords, Description, MetaTitle, Item, Catalog, SmImage, LgImage, RegPrice, SalePrice FROM " .SB_DB_PREFIX ."_items WHERE ID='$item'";
    $metaresult = mysql_query($metaquery, $dblink) or die ("Unable to select item. Try again later.");
    $metanum = mysql_num_rows($metaresult);
    if ($metanum == 1)
    {
    $metarow = mysql_fetch_array($metaresult);
    if ($metarow[Keywords])
    $Meta_Keywords=$metarow[Keywords];
    if ($metarow[Description])
    $Meta_Description=$metarow[Description];
    if ($metarow[MetaTitle])
    $Meta_Title=$metarow[MetaTitle];
    else
    $Meta_Title=$metarow[Item];
    $pagetitle = stripslashes($metarow[Item]);
    $catalog_number = (!empty($metarow[Catalog])) ? '#' . stripslashes($metarow[Catalog]) . ' ' : '';
    // ADDED FOR OPEN GRAPH TAGS
    if(!empty($metarow[LgImage]))
    $pageimg=imgpathtourl($metarow[LgImage]);
    else if(!empty($metarow[SmImage]))
    $pageimg=imgpathtourl($metarow[SmImage]);
    if ($metarow[SalePrice] > 0)
    $pin_price = $metarow[SalePrice];
    else
    $pin_price = $metarow[RegPrice];
    // END OPEN GRAPH TAGS
    }
  6. For Open Graph Tags: Open the meta.php file in the /enc/ folder, and just above the closing PHP tag at the bottom of the page:

    ?>

    add:

    // ADDED FOR OPEN GRAPH TAGS
    if (!empty($Meta_Description) AND !empty($Meta_Title) AND !empty($Site_Name))
    {
    ?>
    
    
    
    
    
    


    else
    {
    ?>

    } } // END OPEN GRAPH TAGS

    and change 'USD' to your three digit currency type, if needed

  7. For Open Graph Tags: For version 2.82 or 2.83 (not required in 2.84), open the products_variables.php file in the /enc/ folder, and change the following code (in the var_smallimage function):

    if ($imgwidth > 0 OR $imgheight > 0)
    {
    $smimg .= "style="";
    if ($imgwidth > 0)
    $smimg .= "width: " .$imgwidth ."px; ";
    if ($imgheight > 0)
    $smimg .= "height: " .$imgheight ."px; ";
    $smimg .= """;
    }
    $smimg .= "border="0">";

    to:

    $smimg .= "style="";
    if ($imgwidth > 0 OR $imgheight > 0)
    {
    if ($imgwidth > 0)
    $smimg .= "width: " .$imgwidth ."px; ";
    if ($imgheight > 0)
    $smimg .= "height: " .$imgheight ."px; ";
    }
    $smimg .= "border: 0;" />";