在对用的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();
}