在Magento的任何页面上获取元描述和页面标题 [英] Get the meta description and page title on any page in Magento

查看:46
本文介绍了在Magento的任何页面上获取元描述和页面标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取Magento中任何页面(产品页面,类别页面,CMS页面和任何其他页面)的元描述和页面标题.这是针对Magento 1.9的.

How can I get the meta description and page title of any page in Magento (product page, category page, CMS page and any other page). This is for 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();
}

但这并不是在所有情况下都有效.有人可以帮忙吗?

But this isnt working in every case. Can anyone help?

推荐答案

要获取任何页面上的页面标题,请使用:

To get the page title on any page, use:

$title = $this->getLayout()->getBlock('head')->getTitle()

要获取任何页面上的元描述,请使用:

To get the meta description on any page, use:

$descr = $this->getLayout()->getBlock('head')->getDescription()

这篇关于在Magento的任何页面上获取元描述和页面标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆