2013-07-16 78 views
4

我們使用WYSIWYG編輯器進行產品描述,其中有HTML標籤。然而,Magento正在使用產品頁面標題中的元內容描述中的所有內容,這使人們在社交網絡上共享頁面時變得很難看,因爲描述是由原始HTML標記組成的。擺脫Magento中產品頁面元描述中的標籤?

例如,在this page,meta描述是這樣的:

<meta name="description" content="&lt;div class=&quot;short-description&quot;&gt; 
&lt;div class=&quot;std&quot;&gt; 
&lt;ul&gt; 
&lt;li&gt;Colored bridesmaid dress made in lace and taffeta&lt;/li&gt; 
&lt;li&gt;The top is made of ivory French corded lace, the skirt is made of colored taffeta&lt;/li&gt; 
&lt;li&gt;Straight front neckline, V Back&lt;/li&gt; 
&lt;li" /> 

我的問題是我怎麼能擺脫標籤,這樣只有文字是在描述中使用?我不知道要看哪個模板。任何幫助,將不勝感激!謝謝!

回答

3

meta標籤呈現在模板app/design/frontend/{interface}/{theme}/template/page/html/head.phtml這樣的:

<meta name="description" content="<?php echo htmlspecialchars($this->getDescription()) ?>" /> 
<meta name="keywords" content="<?php echo htmlspecialchars($this->getKeywords()) ?>" /> 

我認爲你可以strip_tags取代htmlspecialchars。您可能會爲這些標籤獲得更好的價值。
我不明白的是,這是怎麼發生在你身上的。這些產品具有分隔的字段,用於輸入元描述和關鍵字,不使用所見即所得的編輯器。如果您從產品描述中使用某些自動填充這些字段,那麼在填寫字段之前剝離標籤是一個好主意。
[編輯]
你可以嘗試用空格代替標籤,而不是剝奪他們的:

$description = preg_replace('#<[^>]+>#', ' ', $this->getDescription()); 

那麼你可以去掉雙空格

$description = preg_replace('!\s+!', ' ', $description); 
+0

我們需要在產品說明中使用ul列表或ol列表。我們直接從Magento後臺控制檯目錄 - >管理產品添加/編輯產品。有沒有更好的方法? –

+0

我已經用新解決方案更新了答案。 – Marius

+0

在最後的php回聲我用html_entity解碼所以&不會得到像這樣的輸出'echo html_entity_decode($ description)' – asherrard

2

將此文件複製

/app/code/core/Mage/Catalog/Block/Product/View.php 

在此文件夾中(在之前創建!)

app/code/local/Mage/Catalog/Block/Product/View.php 

現在(在Magento 1.9.1.0 67行)找到這段代碼

$description = $product->getMetaDescription(); 
      if ($description) { 
       $headBlock->setDescription(($description)); 
      } else { 
       $headBlock->setDescription(Mage::helper('core/string')->substr($product->getDescription(), 0, 255)); 
      } 

和編輯它像

$description = $product->getMetaDescription(); 
      if ($description) { 
       $headBlock->setDescription(($description)); 
      } else { 
       $strippeddesc = html_entity_decode(strip_tags($product->getDescription())); 
       $headBlock->setDescription(Mage::helper('core/string')->substr($strippeddesc, 0, 255)); 
      } 

我添加了一個$ strippeddesc與內容產品描述,清理和正確解碼。

現在我們可以在google中獲得一些美妙的metadesc ;-)