-
-
Save markomarkovic/3952134 to your computer and use it in GitHub Desktop.
Paging Element for Twitter Bootstrap and CakePHP 2.0+
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php $span = isset($span) ? $span : 8; ?> | |
<?php $page = isset($this->request->params['named']['page']) ? $this->request->params['named']['page'] : 1; ?> | |
<?php $pages = (int)$this->Paginator->counter('{:pages}'); ?> | |
<div class="pagination pagination-centered"> | |
<ul> | |
<?php echo $this->Paginator->prev( | |
'← ' . __('Previous'), | |
array( | |
'escape' => false, | |
'tag' => 'li' | |
), | |
'<a onclick="return false;">← Previous</a>', | |
array( | |
'class'=>'disabled prev', | |
'escape' => false, | |
'tag' => 'li' | |
) | |
);?> | |
<?php | |
$count = $span; | |
if ($page <= $span / 2) { | |
$i = 0; | |
} | |
if ($page > $span / 2) { | |
$i = $page - $span / 2; | |
$count += $i; | |
} | |
if ($page > $pages - ($span / 2)) { | |
$i = $pages - $span; | |
} | |
?> | |
<?php if ($i > 0): ?> | |
<li class="disabled"><span>…</span></li> | |
<?php endif; ?> | |
<?php while ($i++ < $count): ?> | |
<?php $options = ''; ?> | |
<?php if ($i == $page): ?> | |
<?php $options = ' class="active"'; ?> | |
<?php endif; ?> | |
<?php if ($this->Paginator->hasPage($i) && $i > 0): ?> | |
<li<?php echo $options; ?>><?php echo $this->Paginator->link($i, array('page' => $i)); ?></li> | |
<?php endif; ?> | |
<?php endwhile; ?> | |
<?php if ($this->Paginator->hasPage($i) && $i > 0): ?> | |
<li class="disabled"><span>…</span></li> | |
<?php endif; ?> | |
<?php echo $this->Paginator->next( | |
__('Next') . ' →', | |
array( | |
'escape' => false, | |
'tag' => 'li' | |
), | |
'<a onclick="return false;">Next →</a>', | |
array( | |
'class' => 'disabled next', | |
'escape' => false, | |
'tag' => 'li' | |
) | |
);?> | |
</ul> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment