Skip to content

Instantly share code, notes, and snippets.

@adxio
Created October 20, 2015 15:32
Show Gist options
  • Save adxio/8cc4d006bfe14340e48b to your computer and use it in GitHub Desktop.
Save adxio/8cc4d006bfe14340e48b to your computer and use it in GitHub Desktop.
Pagenation
<?php
$build = http_build_query($canonical,'','&');
$last = ceil( $jumlah / $limit );
$links = 3;
$start = ( ( $page - $links ) > 0 ) ? $page - $links : 1;
$end = ( ( $page + $links ) < $last ) ? $page + $links : $last;
if($page == 1){
print '<link rel="next" href="'.$canonical_url.'&page=' . ( $page + 1 ) . '" />';
}elseif ($page == $end) {
print '<link rel="prev" href="'.$canonical_url.'&page=' . ( $page - 1 ) . '" />';
}elseif ($page != $end && $page != 1) {
print '<link rel="prev" href="'.$canonical_url.'&page=' . ( $page - 1 ) . '" />';
print '<link rel="next" href="'.$canonical_url.'&page=' . ( $page + 1 ) . '" />';
}
$html = '<ul class="pagination">';
$class = ( $page == 1 ) ? "disabled" : "";
$html .= '<li class="' . $class . '"><a href="?'.$build.'&page=' . ( $page - 1 ) . '">&laquo;</a></li>';
if ( $start > 1 ) {
$html .= '<li><a href="?'.$build.'&page=1">1</a></li>';
$html .= '<li class="disabled"><span>...</span></li>';
}
for ( $i = $start ; $i <= $end; $i++ ) {
$class = ( $page == $i ) ? "active" : "";
$html .= '<li class="' . $class . '"><a href="?'.$build.'&page=' . $i . '">' . $i . '</a></li>';
}
if ( $end < $last ) {
$html .= '<li class="disabled"><span>...</span></li>';
$html .= '<li><a href="?'.$build.'&page=' . $last . '">' . $last . '</a></li>';
}else{
$html .= '<link rel="next" href="'.$canonical_url.'&page=' . ( $page + 1 ) . '"></link>';
}
$class = ( $page == $last ) ? "disabled" : "";
$html .= '<li class="' . $class . '"><a href="?'.$build.'&page=' . ( $page + 1 ) . '">&raquo;</a></li>';
$html .= '</ul>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment