Magento:将“产品列表寻呼机” - 块放入

时间:2011-09-30 11:45:10

标签: magento

我有以下问题: 我希望使用rel =“next”和rel =“prev”为magento产品列表开发分页。 http://googlewebmastercentral.blogspot.com/2011/09/pagination-with-relnext-and-relprev.html 如何访问寻呼机?当分页器块将被渲染时,头部块已经被渲染......

我的问题有解决办法吗?

3 个答案:

答案 0 :(得分:1)

是的,您可以编辑以下文件:

/app/design/frontend//default/template/page/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 =“...”,同样适用于“下一步”链接;)

答案 1 :(得分:1)

我将此代码添加到head.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
        }
    ?>

答案 2 :(得分:1)

从版本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 .'" />';
}