我有以下问题:我想开发分页与rel= " next "和rel= " prev "的magento产品列表。http://googlewebmastercentral.blogspot.com/2011/09/pagination-with-relnext-and-relprev.html我怎样才能进入寻呼机?当分页块被渲染时,标题块已经被渲染了…
我的问题有什么解决办法吗?是的,您可以编辑以下文件:
/app/设计/前端//默认/模板/页面/html/pager.phtml
你可以看到,例如:
<?php if (!$this->isFirstPage()): ?>
<li>
<a class="previous<?php if(!$this->getAnchorTextForPrevious()): ?> i-previous<?php endif;?>" href="<?php echo $this->getPreviousPageUrl() ?>" title="<?php echo $this->__('Previous') ?>">
<?php echo $this->__("Previous");?>
</a>
</li>
<?php endif;?>
你可以很容易地添加rel="…"你想要的链接,同样适用于"Next"链接;)
我将这段代码添加到头部。phtml文件…
<?php
$actionName = $this->getAction()->getFullActionName();
if($actionName == 'catalog_category_view') // Category Page
{
$id = Mage::app()->getRequest()->getParam('id', false); //cat id
$category = Mage::getModel('catalog/category')->load($id);
$prodCol = $category->getProductCollection();
$tool = $this->getLayout()->createBlock('catalog/product_list_toolbar')->setCollection($prodCol);
$linkPrev = false;
$linkNext = false;
if ($tool->getCollection()->getSize()) {
if ($tool->getLastPageNum() > 1) {
if (!$tool->isFirstPage()) {
$linkPrev = true;
$prevUrl = $tool->getPreviousPageUrl();
}
if (!$tool->isLastPage()) {
$linkNext = true;
$nextUrl = $tool->getNextPageUrl();
}
}
}
?>
<?php if ($linkPrev): ?>
<link rel="prev" href="<?php echo $prevUrl ?>" />
<?php endif; ?>
<?php if ($linkNext): ?>
<link rel="next" href="<?php echo $nextUrl ?>" />
<?php endif; ?>
<?php
}
?>
从版本1.5这个解决方案不再工作,这是我的解决方案:
$actionName = $this->getAction()->getFullActionName();
if($actionName == 'catalog_category_view') // Category Page
{
$id = Mage::app()->getRequest()->getParam('id', false); //cat id
$category = Mage::getModel('catalog/category')->load($id);
$prodCol = $category->getProductCollection()->addAttributeToFilter('status', 1)->addAttributeToFilter('visibility', array('in' => array(2, 4)));
$tool = $this->getLayout()->createBlock('page/html_pager')->setLimit($this->getLayout()->createBlock('catalog/product_list_toolbar')->getLimit())->setCollection($prodCol);
$linkPrev = false;
$linkNext = false;
if ($tool->getCollection()->getSize()){
if ($tool->getLastPageNum() > 1){
if (!$tool->isFirstPage()) {
$linkPrev = true;
if($tool->getCurrentPage()==2){
$url = explode('?',$tool->getPreviousPageUrl());
$prevUrl = $url[0];
}
else $prevUrl = $tool->getPreviousPageUrl();
}
if (!$tool->isLastPage()){
$linkNext = true;
$nextUrl = $tool->getNextPageUrl();
}
}
}
if ($linkPrev) echo '<link rel="prev" href="'. $prevUrl .'" />';
if ($linkNext) echo '<link rel="next" href="'. $nextUrl .'" />';
}