Skip to content

Instantly share code, notes, and snippets.

@vilepickle
Last active Aug 29, 2015
Embed
What would you like to do?
Bootstrap 3 Pager for Drupal 6 template.php entry
<?php
function YOURTEMPLATE_pager($tags = array(), $limit = 10, $element = 0, $parameters = array()) {
global $pager_page_array, $pager_total;
$page_prev = $pager_page_array[$element] - 1;
$page_curr = $pager_page_array[$element] + 1;
$page_next = $pager_page_array[$element] + 1;
$page_last = $pager_total[$element] - 1;
if ($pager_total[$element] > 1) {
$output = '<ul class="pagination">';
if ($pager_page_array[$element]!=0) {
$output.= '<li><a href="?page=0">First</a></li>';
$output.= '<li><a href="?page='.$page_prev.'">Prev</a></li>';
} else {
$output.= '<li class="disabled"><span>First</span></li>';
$output.= '<li class="disabled"><span>Prev</span></li>';
}
$num_page_links = 5;
if($pager_total[$element] <= $num_page_links) {
$pagenumbers_start = 1;
$pagenumbers_end = $pager_total[$element];
} else {
if($page_curr <= ceil($num_page_links/2)) {
$pagenumbers_start = 1;
$pagenumbers_end = $num_page_links;
} else if ($page_curr >= $pager_total[$element] - floor($num_page_links / 2)) {
$pagenumbers_start = $pager_total[$element] - $num_page_links + 1;
$pagenumbers_end = $pager_total[$element];
} else {
$pagenumbers_start = $page_curr - floor(($num_page_links - 1) / 2);
$pagenumbers_end = $page_curr + ceil(($num_page_links - 1) / 2);
}
}
if($pagenumbers_start > 1) $output .= ' <li class="disabled"><span>...</span></li> ';
for($i = $pagenumbers_start; $i <= $pagenumbers_end; $i++) {
if($i == $page_curr) $output .= ' <li class="active"><a href="#">'.$page_curr.'</a></li> ';
else $output .= '<li><a href="?page='.($i-1).'">'.$i.'</a></li>';
}
if($pager_total[$element] > $pagenumbers_end) $output .= ' <li class="disabled"><span>...</span></li> ';
if ($page_curr!=$pager_total[$element]) {
$output.= '<li><a href="?page='.$page_next.'">Next</a></li>';
$output.= '<li><a href="?page='.$pager_total[$element].'">Last</a></li>';
} else {
$output.= '<li class="disabled"><span>Next</span></li>';
$output.= '<li class="disabled"><span>Last</span></li>';
}
$output.= '</ul>';
return $output;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment