Untitled

mail@pastecode.io avatar
unknown
php
2 years ago
2.9 kB
3
Indexable
Never
<?php
// Original by Hasan
// ubahan by Nug

// How many adjacent pages should be shown on each side?
if(!isset($adjacents))  $adjacents  = 4;            // configable
if(!isset($ellipsis))   $ellipsis   = '&hellip;';   // configable

$max_length = ($adjacents * 2) + 1;
$current_page = $this->uri->param(array(__('hlm') => 1));
$ellipsis = '<span class="disabled"><a href="javascript:void(0)">'.$ellipsis.'</a></span>';
?>

<div class="pagination col-md-12">
<div class="pagination-style1 text-left">
<?php if ($has_previous): ?>
<!-- prev link -->
    <span class="page-link"><?php echo anchor(uri_write_param(array(__('hlm') => $previous_page)), '<i class="fa fa-angle-left"></i>', 'title="'.__('Back').'"'); ?></span>
<?php else: ?>
    <span class="page-link disabled"><a href="javascript:void(0)"><i class="fa fa-angle-left"></i></a></span>
<?php endif; ?>

<?php
// page link
if ($total_pages <= $max_length) //not enough pages to bother breaking it up
{
    for ($i = 1; $i <= $total_pages; $i++)
    {
        echo '<span class="page-link" '.($current_page == $i ? 'class="active"':'').'>'.anchor(uri_write_param(array(__('hlm') => $i)), $i).'</span>';
    }
}
elseif ($total_pages > $max_length) //enough pages to hide some
{
    //close to beginning; only hide later pages
    if ($current_page <= $adjacents + 1)
    {
        for ($i = 1; $i <= $max_length; $i++)
        {
            echo '<span class="page-link" '.($current_page == $i ? 'class="active"':'').'>'.anchor(uri_write_param(array(__('hlm') => $i)), $i).'</span>';
        }
        if ($has_next) echo $ellipsis;
    }
    //in middle; hide some front and some back
    elseif($total_pages - $adjacents > $current_page && $current_page > $adjacents)
    {
        if ($has_previous) echo $ellipsis;
        for ($i = $current_page - $adjacents; $i <= $current_page + $adjacents; $i++)
        {
            echo '<span class="page-link" '.($current_page == $i ? 'class="active"':'').'>'.anchor(uri_write_param(array(__('hlm') => $i)), $i). '</span>';
        }
        if ($has_next) echo $ellipsis;
    }
    //close to end; only hide early pages
    else
    {
        if ($has_previous) echo $ellipsis;
        for ($i = $total_pages - ($max_length-1); $i <= $total_pages; $i++)
        {
            echo '<span class="page-link" '.($current_page == $i ? 'class="active"':'').'>'.anchor(uri_write_param(array(__('hlm') => $i)), $i).'</span>';
        }
    }
}
?>

<?php if ($has_next): ?>
<!-- next link -->
    <span class="page-link"><?php echo anchor(uri_write_param(array(__('hlm') => $next_page)), '<i class="fa fa-angle-right"></i>', 'title="'.__('Lanjut').'"'); ?></span>
<?php else: ?>
    <span class="page-link disabled"><a href="javascript:void(0)"><i class="fa fa-angle-right"></i></a></span>
<?php endif; ?>
</div>
</div>