你好,我想把分类分页的rel=“下一页”和rel=“上一页”标签放入我的magento网站的一部分。有关rel=“next”和rel=“prev”标签的详细信息,请参阅http://googlewebmastercentral.blogspot.com/2011/09/pagination-with-relnext-and-relprev.html。
我正在使用Magento: Put "product list pager"-block in 上发布的来自shadowice222的代码。
<?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
}
?>我有一个问题,在我的第二个分页页面上是一个
<link rel="prev" href="http://www.website.de/category1.html?p=1" />这应该是
<link rel="prev" href="http://www.website.de/category1.html" />就像普通的类别url,它是普通的首页。否则,谷歌将会被搞糊涂。有没有人可以帮我把rel=的“prev”标签从第二页改为第一页。其他一切都运行得很好。非常提前感谢您。
发布于 2011-12-29 11:51:56
我会考虑在代码中添加一些东西来设置前面的url链接:
<?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;
// check here for being on the second page
if ($tool->getCollection->getCurPage() == 2) {
// set the page to the first page correctly
$url = explode('?', $this->helper('core/url')->getCurrentUrl());
$prevUrl = $url[0];
} else {
// retrieve the "normal" previous url
$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
}
?>发布于 2012-04-13 18:55:56
只需阅读Inchoo.net -> http://inchoo.net/ecommerce/magento/how-to-implement-relprev-and-relnext-to-magentos-pagination/上的新博客
他们对代码做了一些调整
而不是
$id = Mage::app()->getRequest()->getParam('id', false); //cat id
$category = Mage::getModel('catalog/category')->load($id);他们使用
$category = Mage::registry('current_category');在我看来要干净一点。
发布于 2012-09-24 17:52:45
最简单的方法是用一个简单的字符串replace将其从字符串中删除:
<?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->getCollection->getCurPage() == 2) {
$prevUrl = str_replace('p=1&', '', $prevUrl);
}
}
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
}
?>显然,更好的方法是使用Magento解析该url,并取消设置pagenumber查询参数(从适当的位置依次拉出查询参数'p‘)。
https://stackoverflow.com/questions/8661332
复制相似问题