-
-
Save AlkarE/18631cc7750b7cd965f714faef46147d to your computer and use it in GitHub Desktop.
Zurb Foundation Pagination Function for WordPress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function foundation_pagination($before = '', $after = '') { | |
global $wpdb, $wp_query; | |
$request = $wp_query->request; | |
$posts_per_page = intval(get_query_var('posts_per_page')); | |
$paged = intval(get_query_var('paged')); | |
$numposts = $wp_query->found_posts; | |
$max_page = $wp_query->max_num_pages; | |
if ( $numposts <= $posts_per_page ) { return; } | |
if(empty($paged) || $paged == 0) { | |
$paged = 1; | |
} | |
$pages_to_show = 7; | |
$pages_to_show_minus_1 = $pages_to_show-1; | |
$half_page_start = floor($pages_to_show_minus_1/2); | |
$half_page_end = ceil($pages_to_show_minus_1/2); | |
$start_page = $paged - $half_page_start; | |
if($start_page <= 0) { | |
$start_page = 1; | |
} | |
$end_page = $paged + $half_page_end; | |
if(($end_page - $start_page) != $pages_to_show_minus_1) { | |
$end_page = $start_page + $pages_to_show_minus_1; | |
} | |
if($end_page > $max_page) { | |
$start_page = $max_page - $pages_to_show_minus_1; | |
$end_page = $max_page; | |
} | |
if($start_page <= 0) { | |
$start_page = 1; | |
} | |
echo $before.'<nav class="page-navigation"><ul class="pagination">'.""; | |
if ($start_page >= 2 && $pages_to_show < $max_page) { | |
$first_page_text = __( 'First' ); | |
echo '<li><a href="'.get_pagenum_link().'" title="'.$first_page_text.'">'.$first_page_text.'</a></li>'; | |
} | |
echo '<li>'; | |
previous_posts_link( __('Previous') ); | |
echo '</li>'; | |
for($i = $start_page; $i <= $end_page; $i++) { | |
if($i == $paged) { | |
echo '<li class="current"> '.$i.' </li>'; | |
} else { | |
echo '<li><a href="'.get_pagenum_link($i).'">'.$i.'</a></li>'; | |
} | |
} | |
echo '<li>'; | |
next_posts_link( __('Next'), 0 ); | |
echo '</li>'; | |
if ($end_page < $max_page) { | |
$last_page_text = __('Last'); | |
echo '<li><a href="'.get_pagenum_link($max_page).'" title="'.$last_page_text.'">'.$last_page_text.'</a></li>'; | |
} | |
echo '</ul></nav>'.$after.""; | |
} /* End page navi */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if ( function_exists('foundation_pagination') ) | |
foundation_pagination(); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment