dongyonglie5132 2016-02-18 12:19
浏览 49
已采纳

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

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.

I have tried something along the lines of:

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?

  • 写回答

1条回答 默认 最新

  • dongren9966 2016-02-18 12:28
    关注

    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()
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥100 已有python代码,要求做成可执行程序,程序设计内容不多
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助
  • ¥15 STM32控制MAX7219问题求解答