Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function sog_use_permalink() {
- if ( get_option('permalink_structure') != '' ) {
- return true;
- } else {
- return false;
- }
- }
- function sog_pagination( $query, $baseURL = '', $range = 2 ) {
- if ( ! $baseURL ) $baseURL = get_bloginfo( 'url' );
- $page = $query->query_vars["paged"];
- $total_pages = $query->max_num_pages;
- if ( !$page ) $page = 1;
- $qs = $_SERVER["QUERY_STRING"] ? "?".$_SERVER["QUERY_STRING"] : "";
- // Only necessary if there's more posts than posts-per-page
- if ( $query->found_posts > $query->query_vars["posts_per_page"] ) {
- echo '<div class="paging">';
- // First link
- if( $page-$range > $range ) {
- if( sog_use_permalink() ) {
- echo '<a class="next" href="'.$baseURL.'/page/1/'.'">First [1]</a>';
- } else {
- echo '<a class="next" href="'.$baseURL.'/'.add_query_arg('paged', '1', $qs).'">First [1]</a>';
- }
- }
- // Previous link?
- if ( $page > 1 ) {
- if( sog_use_permalink() ) {
- echo '<a class="previous" href="'.$baseURL.'/page/'.($page-1).'/'.'">« previous</a>';
- } else {
- echo '<a class="previous" href="'.$baseURL.'/'.add_query_arg('paged', ($page-1), $qs).'">« previous</a>';
- }
- }
- // Loop through pages
- for ( $i=1; $i <= $total_pages; $i++ ) {
- // Current page or linked page?
- if ( $i == $page ) {
- echo '<span class="active">' . $i . '</span>';
- } else {
- if( $i == $page+$range || $i == $page-$range ) {
- if( sog_use_permalink() ) {
- echo '<a href="'.$baseURL.'page/'.$i.'/">'.$i.'</a>';
- } else {
- echo '<a href="'.$baseURL.add_query_arg('paged', $i, $qs).'">'.$i.'</a>';
- }
- }
- }
- }
- // Next link?
- if ( $page < $total_pages ) {
- if( sog_use_permalink() ) {
- echo '<a class="next" href="'.$baseURL.'/page/'.($page+1).'/'.'">next »</a>';
- } else {
- echo '<a class="next" href="'.$baseURL.'/'.add_query_arg('paged', ($page+1), $qs).'">next »</a>';
- }
- }
- // Last link
- if( $page+$range < $total_pages ) {
- if( sog_use_permalink() ) {
- echo '<a class="next" href="'.$baseURL.'/page/' . $total_pages . '/'.'">Last [' . $total_pages . ']</a>';
- } else {
- echo '<a class="next" href="'.$baseURL.'/'.add_query_arg('paged', ($total_pages), $qs).'">Last [' . $total_pages . ']</a>';
- }
- }
- echo '</div>';
- }
- wp_reset_postdata();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement