由于自己的站用了大量的属性过滤功能.虽然这样做,用户体验非常的好.但是,牺牲了seo的性能.
首先是层导航页面的url并不友好.再次是层导航页面的meta等信息也不好书写..
url的问题.发现可以使用插件实现. 下面的文章,是我google以后,发现已经解决的问题.(原文请点击这里)
english to chinese:
总所周知,magento的seo性能不是非常完美.这就是为什么我的代码会让seo更好的原因:)
我的这个方案,使magento不管多少个分类子页面的标题(title)和元标记(meta)在使用层导航的情况下,title和meta都会自行更改.(默认情况下,层导航和其分类的meta和title都是一样的,这就是google参考重复页面的常见原因之一.)
首先,我们先创建这个文件:
app/code/local/Mage/Page/Block/Html/Head.php
使用这个方法(method)时,所有的活动的过滤器的名字(也就是选了层导航的属性)和当前层导航的值传递给$layerFilters.
这个方法(method)支持排序(order by *)和分页.
public $layerFilters;
public $currentFilters;
public $orderBy;
public $currentPage;
public function getLayersMeta(){
$this->layerFilters = '';
$state_block = $this->getLayout()->createBlock("catalog/layer_state");
$this->currentFilters = $state_block->getActiveFilters();
if(!empty($this->currentFilters)) {
foreach($this->currentFilters as $filter) {
$this->layerFilters .= ($this->layerFilters!='') ? ', '.$filter->getName() : $filter->getName();
$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', $filter->getFilter()->getRequestVar());
foreach($attribute->getSource()->getAllOptions(true, true) as $option) {
if($filter->getValue() == $option['value']) {
$this->layerFilters .= ' - '.strtr($option['label'],array('"'=>"''"));
}
}
}
$this->layerFilters = ($this->layerFilters!='') ? $this->__('Shopping by: ').$this->layerFilters.' - ' : '';
}
$this->orderBy = '';
if($this->getRequest()->getParam('order') && $this->getRequest()->getParam('dir')) {
$this->orderBy .= $this->__('Sort by ').$this->__(htmlspecialchars($this->getRequest()->getParam('order')));
$this->orderBy .= (htmlspecialchars($this->getRequest()->getParam('dir')) == 'asc') ? ', '.$this->__('ascending') : ', '.$this->__('descending');
}
if($this->getRequest()->getParam('limit') && is_numeric($this->getRequest()->getParam('limit'))) {
$this->orderBy .= (($this->orderBy!='') ? ', ' : $this->__('show')).' '.$this->getRequest()->getParam('limit').' '.$this->__('per page');
}
if($this->getRequest()->getParam('p') && is_numeric($this->getRequest()->getParam('p'))) {
$this->currentPage = $this->__('Page').' '.$this->getRequest()->getParam('p').' - ';
}
$this->orderBy = ($this->orderBy!='') ? $this->orderBy.' - ' : '';
return $this->layerFilters.$this->orderBy.$this->currentPage;
}
下一步,将两种方法在同一个文件((getDescription() oraz getTitle()))以这种方式进行修改:
public function getDescription()
{
if (empty($this->_data['description'])) {
$this->_data['description'] = Mage::getStoreConfig('design/head/default_description');
}
return $this->getLayersMeta().$this->_data['description'];
}
public function getTitle()
{
if (empty($this->_data['title'])) {
$this->_data['title'] = $this->getDefaultTitle();
}
return $this->getLayersMeta().htmlspecialchars(html_entity_decode(trim($this->_data['title']), ENT_QUOTES, 'UTF-8'));
}