2016-12-10 15 views
0

我想僅在Magento中爲PDP(產品詳細信息頁)添加OG標籤到產品詳細信息頁面。Magento v1.9.x您如何自定義產品詳細信息頁面的頭部代碼?

有沒有辦法,只能爲PDP head標籤之間添加代碼?

我正在考慮的兩種方法: 1)是否有一個只有我可以編輯的PDP的head.phtml(我只是不知道)? = - 或 - = 2)調整常規頭包括以某種方式查看頁面並將數據轉儲出來。

NOTES(這是): Magento的1.x版(我的商店更新爲1.9.2)。該代碼是僅用於PDP的產品數據。

謝謝你提前。

回答

0

首先,你需要檢查當前頁面是商品詳細頁,那麼你必須通過或者通過控制器或路由器進行檢查。在這裏我們檢查了使用控制器。 轉到head.phtml文件編寫下面的代碼。

<?php 
$this->getRequest()->getControllerName(); 
if($this->getRequest()->getControllerName()=='product') {?> 
    <?php // write your og tag here for eg. ?> 
    <meta property="og:type" content="website" /> 


<?php } 

?> 
0

可以使用處理器catalog-product-view目標商品詳細頁。讓local.xml在你的主題,並在你的操作添加

<catalog_product_view> 
     <reference name="head"> 
     // your action 
     </reference> 
    </catalog_product_view> 

你可以嘗試<action method="addCss」><action method="addJs"><![CDATA[/]]>設置在頭什麼。

0
<? if(Mage::registry('current_product')){ //your product page only code } ?> 

上述if語句只有在產品頁面上纔會返回true。 你應該可以使用它來添加產品頁面的獨家代碼到你的頭部.phtml

相關問題