2011-12-12 30 views
2

我正在處理一個奇怪的問題。在我的產品列表頁面中,分頁不能正常工作。 我一共有187個項目。在分頁中,顯示的頁面數量是三個。即; 1,2,3 當我選擇每頁45個記錄並選擇第4頁時,項目加載正確,但分頁鏈接仍顯示爲1,2,3,4而不是2,3,4。Magento分頁 - 每頁記錄數爲45時頁碼不能正確顯示

我現在用的模板是前端\ myCompany的\ DEFAULT \模板\頁/ HTML/pager.phtml 和塊MageWorx_SeoSuite_Block_Page_Html_Pager。

對於記錄數15和30,分頁沒有任何問題,只有在每頁選擇45條記錄時纔會出現問題。

pager.phtml的內容是,

<?php if($this->getCollection()->getSize()): ?> 

<?php if($this->getUseContainer()): ?> 
<div class="pager"> 
<?php endif ?> 

<?php if($this->getShowAmounts()): ?> 
<p class="amount"> 
    <?php if($this->getLastPageNum()>1): ?> 
     <?php echo $this->__('Items %s to %s of %s total', $this->getFirstNum(), $this->getLastNum(), $this->getTotalNum()) ?> 
    <?php else: ?> 
     <strong><?php echo $this->__('%s Item(s)', $this->getTotalNum()) ?></strong> 
    <?php endif; ?> 
</p> 
<?php endif ?> 

<?php if($this->getShowPerPage()): ?> 
<div class="limiter"> 
    <label><?php echo $this->__('Show') ?></label> 
    <select onchange="setLocation(this.value)"> 
    <?php foreach ($this->getAvailableLimit() as $_key=>$_limit): ?> 
     <option value="<?php echo $this->getLimitUrl($_key) ?>"<?php if($this->isLimitCurrent($_key)): ?> selected="selected"<?php endif ?>> 
      <?php echo $_limit ?> 
     </option> 
    <?php endforeach; ?> 
    </select> <?php echo $this->__('per page') ?> 
</div> 
<?php endif ?> 

<?php if($this->getLastPageNum()>1): ?> 
<div class="pages"> 

    <!-- <strong><?php echo $this->__('Page:') ?></strong>--> 
    <ol> 
    <?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 if(!$this->getAnchorTextForPrevious()): ?> 
        <img src="<?php echo $this->getSkinUrl('images/pager_arrow_left.gif') ?>" alt="<?php echo $this->__('Previous') ?>" class="v-middle" /> 
       <?php else: ?> 
        <?php echo $this->getAnchorTextForPrevious() ?> 
       <?php endif;?> 
      </a> 
     </li> 
    <?php endif;?> 

    <?php if ($this->canShowFirst()): ?> 
     <li><a class="first" href="<?php echo $this->getFirstPageUrl() ?>">1</a></li> 
    <?php endif;?> 

    <?php if ($this->canShowPreviousJump()): ?> 
     <li><a class="previous_jump" title="" href="<?php echo $this->getPreviousJumpUrl() ?>">...</a></li> 
    <?php endif;?> 

    <?php $i=0;foreach ($this->getFramePages() as $_page):if($i<3): ?> 
     <?php if ($this->isPageCurrent($_page)): ?> 
      <li class="current"><?php echo $_page ?></li> 
     <?php else: ?> 
      <li><a href="<?php echo $this->getPageUrl($_page) ?>"><?php echo $_page ?></a></li> 
     <?php endif;?> 
    <?php $i++;endif; endforeach;?> 


    <?php if ($this->canShowNextJump()): ?> 
     <li><a class="next_jump" title="" href="<?php echo $this->getNextJumpUrl() ?>">...</a></li> 
    <?php endif;?> 

    <?php if ($this->canShowLast()): ?> 
     <li><a class="last" href="<?php echo $this->getLastPageUrl() ?>"><?php echo $this->getLastPageNum() ?></a></li> 
    <?php endif;?> 

    <?php if (!$this->isLastPage()): ?> 
     <li> 
      <a class="next<?php if(!$this->getAnchorTextForNext()): ?> i-next<?php endif; ?>" href="<?php echo $this->getNextPageUrl() ?>" title="<?php echo $this->__('Next') ?>"> 
       <?php if(!$this->getAnchorTextForNext()): ?> 
        <img src="<?php echo $this->getSkinUrl('images/pager_arrow_right.gif') ?>" alt="<?php echo $this->__('Next') ?>" class="v-middle" /> 
       <?php else: ?> 
        <?php echo $this->getAnchorTextForNext() ?> 
       <?php endif;?> 
      </a> 
     </li> 
    <?php endif;?> 
    </ol> 

</div> 
<?php endif; ?> 

<?php if($this->getUseContainer()): ?> 
</div> 
<?php endif ?> 

我是一個初學者到Magento的。

回答

2

我修復了這個問題。 在Mage_Page_Block_Html_Pager類有一個受保護的變量$ _displayPages,它被設置爲

protected $_displayPages = 5; // Page length for the navigation 

所以在我pager.html(前端\ myCompany的\ DEFAULT \模板\頁面\ HTML \ pager.phtml)我做了一個小的變化如下

<?php $i=0;foreach ($this->getFramePages() as $_page):if($i<5): ?> 

我們可以根據我們的要求簡單地改變頁面的長度。爲此,只需重寫Mage_Page_Block_Html_Pager類並更改受保護的$ _displayPages變量。

我們還可以設置管理頁面的長度