修改magento页面的title,description等------------进而可以写一个descroption数组,让description随机生成-----方便seo,节省在添加产品的时候添加descrition浪费时间

 

在对用的block文件中加入:一般是content最大的block里面设定,譬如:Mage_Catalog_Block_Category_View

 

 protected function _prepareLayout()

    {

        parent::_prepareLayout();

 

        $this->getLayout()->createBlock('catalog/breadcrumbs');

 

        if ($headBlock = $this->getLayout()->getBlock('head')) {

            $category = $this->getCurrentCategory();

            if ($title = $category->getMetaTitle()) {

                $headBlock->setTitle($title);

            }

            if ($description = $category->getMetaDescription()) {

                $headBlock->setDescription($description);

            }

            if ($keywords = $category->getMetaKeywords()) {

                $headBlock->setKeywords($keywords);

            }

            if ($this->helper('catalog/category')->canUseCanonicalTag()) {

                $headBlock->addLinkRel('canonical', $category->getUrl());

            }

            /*

            want to show rss feed in the url

            */

            if ($this->IsRssCatalogEnable() && $this->IsTopCategory()) {

                $title = $this->helper('rss')->__('%s RSS Feed',$this->getCurrentCategory()->getName());

                $headBlock->addItem('rss', $this->getRssLink(), 'title="'.$title.'"');

            }

        }

 

        return $this;

    }

 

 

例子:

protected function _prepareLayout()

    {

        $this->getLayout()->createBlock('catalog/breadcrumbs');

        if ($headBlock = $this->getLayout()->getBlock('head')) {

            if ($title = $this->getProduct()->getMetaTitle()) {

                $headBlock->setTitle($title);

            }

//title =name以name当title。

else{$headBlock->setTitle($this->getProduct()->getName());}

 

            if ($keyword = $this->getProduct()->getMetaKeyword()) {

                $headBlock->setKeywords($keyword);

            } elseif( $currentCategory = Mage::registry('current_category') ) {

//keyword 这里写keywords

$keywords ="Replica Watches, Rolex Watches";

 

$headBlock->setKeywords($keywords);

 

// $headBlock->setKeywords($this->getProduct()->getName());

            }

 

            if ($description = $this->getProduct()->getMetaDescription()) {

                $headBlock->setDescription( ($description) );

            } else {

//

$zz =$this->getProduct()->getName();

//$arr1 = array($zz."111",$zz."222",$zz."333",$zz."444",$zz."555",$zz."666");

 

//rand  descroption   array!这里写要随机出来的description。

$arr1 = array( 

 

$zz." on sale",

$zz." for sale"

 

);

 

 

 

 

$ss = array_rand($arr1);

 

 

 

 

//

                $headBlock->setDescription($arr1[$ss]);

//$headBlock->setDescription( $this->getProduct()->getDescription() );

            }

        }

 

        return parent::_prepareLayout();

    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值