![](/img/trans.png)
[英]Magento : How to get category page title attribute (meta title) as html page title
[英]Get the meta description and page title on any page in Magento
如何獲取Magento中任何頁面(產品頁面,類別頁面,CMS頁面和任何其他頁面)的元描述和頁面標題。 這是針對Magento 1.9的。
我已經嘗試了以下方法:
if( Mage::registry('current_product') ){ // product page
$product = Mage::registry('current_product');
$title = $product->getMetaTitle();
$descr = $product->getDescription();
}elseif( Mage::registry('current_category') ){ // category page
$category = Mage::registry('current_category');
$title = $category->getTitle();
$descr = $category->getDescription();
}else{ // CMS / any other page
$title = $this->getTitle();
$descr = $this->getDescription();
}
但這在每種情況下都不起作用。 有人可以幫忙嗎?
要獲取任何頁面上的頁面標題,請使用:
$title = $this->getLayout()->getBlock('head')->getTitle()
要獲取任何頁面上的元描述,請使用:
$descr = $this->getLayout()->getBlock('head')->getDescription()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.