想要学习抖音引流?提供在线文档/视频学习资料( 点此查看学习列表 ), 一对一本人微信直接语音教学,填写联系表单 分析账户开启抖音爆粉之旅吧

如何无插件为Magento添加Facebook Open Graph丰富网摘标记?

FTP打开模板文件 /app/design/frontend/rwd/default/template/page/html/head.phtml 蓝色部分根据不同模板会有差异。在<?php echo $this->getCssJsHtml() ?>前插入以下代码即可:

<?php /* Begin Open Graph Protocol for Facebook */ ?>
<?php
if(!function_exists('getPageType')){
function getPageType($type){
    $moduleName=Mage::app()->getRequest()->getModuleName();
    $controllerName=Mage::app()->getRequest()->getControllerName();
    $actionName=Mage::app()->getRequest()->getActionName();
	$cmsHome = Mage::getSingleton('cms/page')->getIdentifier();
	$routeName = Mage::app()->getFrontController()->getRequest()->getRouteName();
	
    $s = strtolower($moduleName.$controllerName);
    if($s==$type){
        return true;
    }elseif($cmsHome=='home' && $routeName==$type){
		return true;
	}
    return false;
}}
$site_name='网站简称';
$product = Mage::registry('current_product');
if(getPageType('catalogproduct')):
if($product && $product->getId()): ?>
    <?php $product = Mage::registry('current_product'); ?>
    <meta property="og:title" content="<?php echo ($product->getName()); ?>" />
    <meta property="og:type" content="product" />
    <meta property="og:image" content="<?php echo $this->helper('catalog/image')->init($product, 'image');?>" />
    <meta property="og:url" content="<?php echo $product->getProductUrl(); ?>" />
    <meta property="og:description" content="<?php echo strip_tags(($product->getShortDescription())); ?>" />
    <meta property="og:site_name" content="<?php echo $site_name; ?>" />
    <meta property="product:price:amount" content="<?php echo $product->getFinalPrice(); ?>" />
    <meta property="og:price:standard_amount" content="<?php echo $product->getPrice(); ?>" />
    <meta property="product:price:currency" content="USD" />
    <meta property="og:availability" content="instock" />
<?php endif ?>	
<?php elseif(getPageType('catalogcategory')): ?>
    <meta property="og:title" content="<?php echo $this->getTitle() ?>" />
    <meta property="og:type" content="product.group" />
    <meta property="og:url" content="<?php echo $this->helper('core/url')->getCurrentUrl();?>" />
    <meta property="og:description" content="<?php echo strip_tags($this->getDescription()) ?>" />
    <meta property="og:site_name" content="<?php echo $site_name; ?>" />
<?php elseif(getPageType('cms')) : ?>
    <meta property="og:title" content="<?php echo $this->getTitle() ?>" />
    <meta property="og:type" content="website" />
    <meta property="og:url" content="<?php echo $this->helper('core/url')->getCurrentUrl();?>" />
    <meta property="og:description" content="<?php echo strip_tags($this->getDescription()) ?>" />
    <meta property="og:site_name" content="<?php echo $site_name; ?>" />
<?php else: ?>
    <meta property="og:title" content="<?php echo $this->getTitle() ?>" />
    <meta property="og:type" content="article" />
    <meta property="og:url" content="<?php echo $this->helper('core/url')->getCurrentUrl();?>" />
    <meta property="og:description" content="<?php echo strip_tags($this->getDescription()) ?>" />
    <meta property="og:site_name" content="<?php echo $site_name; ?>" />
<?php endif; ?>
<?php /* End Open Graph Protocol for Facebook */ ?>

网站简称替换成自己网站的名称即可。

0
封面图
没有账号? 注册  忘记密码?
";s:2:"js";s:114:"