Question

<meta property="og:url" content="<?php echo "http://". $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];?>"/>
<meta property="og:description" content=""/> 
<meta property="og:title" content=""/>
<meta property="og:image" content=""/>

Je l'ai testé avec le fichier head.phtml, mais je ne sais pas comment obtenir des produits tels attributs comme sku, color et images.

J'ai testé avec $this->helper('catalog/image')->init($_product, 'image') trouvé dans media.phtml sur la balise meta et obtenir une page blanche, mais les images sur la vue des produits fonctionnent très bien.

moi qui confond beaucoup.

Était-ce utile?

La solution

Vous devez peut ajouter à l'un de vos fichiers de mise en page:

<catalog_product_view>
    <reference name="head">
        <block type="core/template" name="open-graph" as="open-graph" template="opengraph/product.phtml" />
    </reference>
</catalog_product_view>

Maintenant, vous devez créer le fichier opengraph/product.phtml à l'intérieur vous thème (app/design/frontend/{package}/{theme}/template/) avec le contenu suivant:

<?php $_product = Mage::registry('current_product'); ?>
<?php if ($_product) : ?>
    <meta property="og:url" content="<?php echo "http://". $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];?>"/>
    <meta property="og:description" content="<?php echo htmlspecialchars($_product->getDescription())?>"/> 
    <meta property="og:title" content="<?php echo htmlspecialchars($_product->getName())?>"/>
    <meta property="og:image" content="<?php echo $this->helper('catalog/image')->init($_product, 'image')?>"/>
<?php endif;?>

Si vous avez besoin d'inclure le sku ou color là vous pouvez les obtenir comme ceci:

$sku = $_product->getSku();
$color = $_product->getAttributeText('color');

Vider le cache lorsque vous avez terminé.

Licencié sous: CC-BY-SA avec attribution
Non affilié à magento.stackexchange
scroll top