我已经实现了Zend Pagination,但无法弄清楚如何限制分页中的链接数量。我知道setPageRange,但它并不是我想要的。
目前分页看起来像这样。
< | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | >
但我想要的是这样的:
第1页
< | 1 | 2 | 3 | ... | 14 | 15 | 16 | >
第8页的
< | 1 | 2 | 3 | ... | 7 | 8 | 9 | ... | 14 | 15 | 16 | >
第14页
< | 1 | 2 | 3 | ... | 13 | 14 | 15 | 16 | >
答案 0 :(得分:0)
在这里,我可以给你一个分页帮助脚本,我已经在我的一个应用程序中实现了它,就像你想要的一样。
<?php
if ($this->pageCount) :
$midRange = floor(sizeof($this->pagesInRange) / 2);
if (($this->current + $midRange) < $this->pageCount && $this->pageCount > 5) :
array_pop($this->pagesInRange);
$display_end = true;
endif;
?>
<div class="paginationControl<?php echo $this->position; ?>">
<div class="paginationControl_pages">
<!-- Previous page link -->
<?php if (isset($this->previous)): ?>
<?php if($this->extraVar != "" ){ ?>
<a href="<?php echo $this->url(array_merge($this->extraVar,array('page' => $this->previous))). $this->query; ?>" class="paging-active"> Previous </a>
<?php }else {?>
<a href="<?php echo $this->url(array('page' => $this->previous)). $this->query; ?>" class="paging-active"> Previous </a>
<?php }?>
<?php else: ?>
<span class="paging-active"><strong> Previous </strong></span>
<?php endif; ?>
<span ><?php if (($this->current - $midRange) > $this->first && $this->pageCount > 5): ?></span>
<?php
array_shift($this->pagesInRange);?>
<?php if($this->extraVar != "" ){ ?>
<a href="<?php echo $this->url(array_merge($this->extraVar,array('page' => $this->first))) . $this->query; ?>" ><span class="paging"><?php echo $this->first ?></span></a>...
<?php } else {?>
<a href="<?php echo $this->url(array('page' => $this->first)) . $this->query; ?>" ><span class="paging"><?php echo $this->first ?></span></a>...
<?php }?>
<?php endif; ?>
<!-- Numbered page links -->
<?php foreach ($this->pagesInRange as $page): ?>
<?php if ($page != $this->current): ?>
<?php if($this->extraVar != "" ){ ?>
<a href="<?php echo $this->url(array_merge($this->extraVar,array('page'=>$page))); ?>""><span class="paging"><?php echo $page; ?></span></a>
<?php }else{ ?>
<a href="<?php echo $this->url(array('page'=>$page)); ?>"><span class="paging"><?php echo $page; ?></span></a>
<?php } ?>
<?php else: ?>
<span class="paging-active"><strong><?php echo $page; ?> </strong></span>
<?php endif; ?>
<?php endforeach; ?>
<?php if (!empty($display_end)) :
?>
<?php if($this->extraVar != "" ){ ?>
...<a href="<?php echo $this->url(array_merge($this->extraVar,array('page' => $this->last))) . $this->query; ?>" ><span class="paging"><?php echo $this->last ?></span></a>
<?php }else{?>
...<a href="<?php echo $this->url(array('page' => $this->last)) . $this->query; ?>" ><span class="paging"><?php echo $this->last ?></span></a>
<?php }?>
<?php endif; ?>
<!-- Next page link -->
<?php if (isset($this->next)): ?>
<?php if($this->extraVar != "" ){ ?>
<a href="<?php echo $this->url(array_merge($this->extraVar,array('page' => $this->next))) . $this->query; ?>" class="paging-active"> Next </a>
<?php }else{?>
<a href="<?php echo $this->url(array('page' => $this->next)) . $this->query; ?>" class="paging-active"> Next </a>
<?php }?>
<?php else: ?>
<span class="paging-active"><strong>Next </strong></span>
<?php endif; ?>
</div>
</div>
<?php endif; ?>
希望这一定会帮助你获得你想要的输出。
答案 1 :(得分:0)
使用此选项将产生所需的输出。
例如,最后一个数字为20,第一个数字为1,当前值为8,限制为3个链接将产生输出
首先,1,..,7,8,9,..,20,最后
indices