在 Magento 的任何页面上获取元描述和页面标题

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()