rel=“下一个”和 rel=“上一个”用于magento分页
您好,我想将用于类别分页的 rel=“next” 和 rel=“prev” 标签放入我的 magento 网站的部分中。有关 rel=“next” 和 rel=“prev” 标记的详细信息,请参阅 http://googlewebmastercentral.blogspot.com/2011/09/pagination-with-relnext-and-relprev.html。
我正在使用 Magento: Put “产品列表分页器”上发布的 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" 标签从第二页更改为第一页。其他一切都工作正常。预先非常感谢您。
Hello I want to put the rel=“next” and rel=“prev” tag for category pagination into the section of my magento website. For detials on the rel=“next” and rel=“prev” tag see http://googlewebmastercentral.blogspot.com/2011/09/pagination-with-relnext-and-relprev.html.
I am using the code from shadowice222 posted on Magento: Put "product list pager"-block in <head>.
<?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
}
?>
I got the problem, that on my second paginated page the is a
<link rel="prev" href="http://www.website.de/category1.html?p=1" />
This should be
<link rel="prev" href="http://www.website.de/category1.html" />
like the normal category url, which is the normal first page. Otherwise Google will be confused. Can anybody help me out in just changing the rel="prev" tag from the second to the first page. Everything else is working just fine. Thank you very much in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我会考虑在设置前一个 url 链接的代码中添加一些内容:
I would look at adding something into the code that sets up the previous url link:
刚刚在 Inchoo.net 上阅读了一篇新博客 ->
http://inchoo.net/ ecommerce/magento/how-to-implement-relprev-and-relnext-to-magentos-pagination/
他们对代码做了一些调整,
而不是
他们使用的
对我来说似乎更干净。
Just read a new blog on Inchoo.net ->
http://inchoo.net/ecommerce/magento/how-to-implement-relprev-and-relnext-to-magentos-pagination/
They've tweaked the code a bit
instead of
they use
seems a bit more clean to me.
最简单的方法就是通过简单的字符串替换将其从字符串中删除:
显然,更好的方法是使用 Magento 解析该 url,并取消设置 pagenumber 查询参数(依次从合适的地方)。
The easiest way is just remove it from the string with a simple string replace:
Obviously, the better way would be better to use Magento to parse that url, and unset the pagenumber query parameter (pulling in turn the query parameter 'p' from the appropriate place).
就我而言,我想将上一个和下一个链接合并到默认分页中,因此我将 $this->getPagerHtml() 替换为:
In my case I want to incorporate the prev and next links inside the defaut paging so I replaced $this->getPagerHtml() by this :