Skip to content

Instantly share code, notes, and snippets.

@ccurtin
Last active October 7, 2016 18:01
Show Gist options
  • Select an option

  • Save ccurtin/7fce58f073e4996bfbb0 to your computer and use it in GitHub Desktop.

Select an option

Save ccurtin/7fce58f073e4996bfbb0 to your computer and use it in GitHub Desktop.
pagination
<?php
function pagination($pages = '', $range = 2)
{
$showitems = ($range * 2)+1;
global $paged;
if(empty($paged)) $paged = 1;
if($pages == '')
{
global $wp_query;
$pages = $wp_query->max_num_pages;
if(!$pages)
{
$pages = 1;
}
}
if(1 != $pages)
{
echo "<div class=\"pagination\"><span>Page ".$paged." of ".$pages."</span>";
if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>&laquo; First</a>";
if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>&lsaquo; Previous</a>";
for ($i=1; $i <= $pages; $i++)
{
if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
{
echo ($paged == $i)? "<span class=\"current\">".$i."</span>":"<a href='".get_pagenum_link($i)."' class=\"inactive\">".$i."</a>";
}
}
if ($paged < $pages && $showitems < $pages) echo "<a href=\"".get_pagenum_link($paged + 1)."\">Next &rsaquo;</a>";
if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>Last &raquo;</a>";
echo "</div>\n";
}
}
?>
<style>
// PAGINATION
.pagination {
clear:both;
padding:20px 0;
position:relative;
font-size:11px;
line-height:13px;
display:inline-table;
width:100%;
}
.pagination span, .pagination a {
display:block;
float:left;
margin: 2px 2px 2px 0;
padding:6px 9px 5px 9px;
text-decoration:none;
width:auto;
color:#fff;
background: #555;
display: table-cell;
float: none;
width: 14.2857%;
text-align: center;
white-space: nowrap;
border-right: 1px solid #FFF;
&:last-child{
border-right:0;
}
}
.pagination a:hover{
color:#fff;
background: #9A7F67;
}
.pagination .current{
padding:6px 9px 5px 9px;
background: #9A7F67;
color:#fff;
}
</style>
<?php if (function_exists("pagination")) {
pagination($additional_loop->max_num_pages);
} ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment