Skip to content

Instantly share code, notes, and snippets.

@adicahyaludin
Created October 5, 2021 17:55
Show Gist options
  • Save adicahyaludin/34c2b6a77e810ab09a9e1784b09f4b07 to your computer and use it in GitHub Desktop.
Save adicahyaludin/34c2b6a77e810ab09a9e1784b09f4b07 to your computer and use it in GitHub Desktop.
php nav number
<?php
$max_num_pages = $results->max_num_pages; // total max pages
$pg = $pg; // current page
$min_nav = $pg-2;
if ( $min_nav < 1 ) :
$min_nav = 1;
endif;
$max_nav = $pg+2;
if ( $max_nav > $max_num_pages ) :
$max_nav = $max_num_pages;
endif;
?>
<?php
if ( $max_num_pages > 1 ) :
?>
<nav class="sppob-nav">
<?php
if ( $pg > 1 ) :
?>
<a href="<?php echo '?pg=1'; ?>" title="<?php _e('First'); ?>"><?php _e('<<'); ?></a>
<?php
endif;
?>
<?php
if ( $min_nav != $pg ) :
?>
<a href="<?php echo '?pg='.($pg-1); ?>" title="<?php _e('Prev'); ?>"><?php _e('<'); ?></a>
<?php
endif;
?>
<?php
for ( $i = $min_nav; $i <= $max_nav; $i++ ) :
?>
<?php
if ( $i == $pg ) :
$active = 'active';
else:
$active = '';
endif;
?>
<a class="<?php echo $active; ?>" href="<?php echo '?pg='.$i; ?>"><?php echo $i; ?></a>
<?php
endfor;
?>
<?php
if ( $max_nav != $pg ) :
?>
<a href="<?php echo '?pg='.($pg+1); ?>" title="<?php _e('Next'); ?>"><?php _e('>'); ?></a>
<?php
endif;
?>
<?php
if ( $pg < $max_num_pages ) :
?>
<a href="<?php echo '?pg='.$max_num_pages; ?>" title="<?php _e('Last'); ?>"><?php _e('>>'); ?></a>
<?php
endif;
?>
</nav>
<?php
endif;
?>
/*
nav
*/
.sppob-nav {
text-align: center;
margin-top: 30px;
}
.sppob-nav a {
background: #242424 !important;
display: inline-block;
padding: 6px 12px 5px;
margin: 5px;
border: 1px solid #2F2F2F;
font-family: "Poppins", Sans-serif;
font-size: 14px;
font-weight: normal;
line-height: 1.9;
}
.sppob-nav a:hover,
.sppob-nav a.active {
color: #E00914 !important;
font-weight: bold;
border: 1px solid #2F2F2F;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment