mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-23 01:27:36 +01:00
paginate_links() from mdawaffe. fixes #3159
git-svn-id: http://svn.automattic.com/wordpress/trunk@4275 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
b5741c1270
commit
60394dd674
@ -84,15 +84,15 @@ class WP_User_Search {
|
||||
|
||||
function do_paging() {
|
||||
if ( $this->total_users_for_query > $this->users_per_page ) { // have to page the results
|
||||
$prev_page = ( $this->page > 1) ? true : false;
|
||||
$next_page = ( ($this->page * $this->users_per_page) < $this->total_users_for_query ) ? true : false;
|
||||
$this->paging_text = '';
|
||||
if ( $prev_page )
|
||||
$this->paging_text .= '<p class="alignleft"><a href="' . add_query_arg(array('usersearch' => $this->search_term, 'userspage' => $this->page - 1), 'users.php?') . '">« Previous Page</a></p>';
|
||||
if ( $next_page )
|
||||
$this->paging_text .= '<p class="alignright"><a href="' . add_query_arg(array('usersearch' => $this->search_term, 'userspage' => $this->page + 1), 'users.php?') . '">Next Page »</a></p>';
|
||||
if ( $prev_page || $next_page )
|
||||
$this->paging_text .= '<br style="clear:both" />';
|
||||
$this->paging_text = paginate_links( array(
|
||||
'total' => ceil($this->total_users_for_query / $this->users_per_page),
|
||||
'current' => $this->page,
|
||||
'prev_text' => '« Previous Page',
|
||||
'next_text' => 'Next Page »',
|
||||
'base' => 'users.php?%_%',
|
||||
'format' => 'userspage=%#%',
|
||||
'add_args' => array( 'usersearch' => urlencode($this->search_term) )
|
||||
) );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -877,4 +877,82 @@ function language_attributes() {
|
||||
|
||||
echo $output;
|
||||
}
|
||||
|
||||
function paginate_links( $arg = '' ) {
|
||||
if ( is_array($arg) )
|
||||
$a = &$arg;
|
||||
else
|
||||
parse_str($arg, $a);
|
||||
|
||||
// Defaults
|
||||
$base = '%_%'; // http://example.com/all_posts.php%_% : %_% is replaced by format (below)
|
||||
$format = '?page=%#%'; // ?page=%#% : %#% is replaced by the page number
|
||||
$total = 1;
|
||||
$current = 0;
|
||||
$show_all = false;
|
||||
$prev_next = true;
|
||||
$prev_text = __('« Previous');
|
||||
$next_text = __('Next »');
|
||||
$end_size = 1; // How many numbers on either end including the end
|
||||
$mid_size = 2; // How many numbers to either side of current not including current
|
||||
$type = 'plain';
|
||||
$add_args = false; // array of query args to aadd
|
||||
|
||||
extract($a);
|
||||
|
||||
// Who knows what else people pass in $args
|
||||
$total = (int) $total;
|
||||
$current = (int) $current;
|
||||
$end_size = 0 < (int) $end_size ? (int) $end_size : 1; // Out of bounds? Make it the default.
|
||||
$mid_size = 0 <= (int) $mid_size ? (int) $mid_size : 2;
|
||||
$add_args = is_array($add_args) ? $add_args : false;
|
||||
$r = '';
|
||||
$page_links = array();
|
||||
$n = 0;
|
||||
$dots = false;
|
||||
|
||||
if ( $prev_next && $current && 1 < $current ) :
|
||||
$link = str_replace('%_%', 2 == $current ? '' : str_replace('%#%', $current - 1, $format), $base);
|
||||
if ( $add_args )
|
||||
$link = add_query_arg( $add_args, $link );
|
||||
$page_links[] = "<a class='prev page-numbers' href='" . wp_specialchars( $link, 1 ) . "'>$prev_text</a>";
|
||||
endif;
|
||||
for ( $n = 1; $n <= $total; $n++ ) :
|
||||
if ( $n == $current ) :
|
||||
$page_links[] = "<span class='page-numbers current'>$n</span>";
|
||||
$dots = true;
|
||||
else :
|
||||
if ( $show_all || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) :
|
||||
$link = str_replace('%_%', 1 == $n ? '' : str_replace('%#%', $n, $format), $base);
|
||||
if ( $add_args )
|
||||
$link = add_query_arg( $add_args, $link );
|
||||
$page_links[] = "<a class='page-numbers' href='" . wp_specialchars( $link, 1 ) . "'>$n</a>";
|
||||
$dots = true;
|
||||
elseif ( $dots && !$show_all ) :
|
||||
$page_links[] = "<span class='page-numbers dots'>...</span>";
|
||||
$dots = false;
|
||||
endif;
|
||||
endif;
|
||||
endfor;
|
||||
if ( $prev_next && $current && ( $current < $total || -1 == $total ) ) :
|
||||
$link = str_replace('%_%', str_replace('%#%', $current + 1, $format), $base);
|
||||
if ( $add_args )
|
||||
$link = add_query_arg( $add_args, $link );
|
||||
$page_links[] = "<a class='next page-numbers' href='" . wp_specialchars( $link, 1 ) . "'>$next_text</a>";
|
||||
endif;
|
||||
switch ( $type ) :
|
||||
case 'array' :
|
||||
return $page_links;
|
||||
break;
|
||||
case 'list' :
|
||||
$r .= "<ul class='page-numbers'>\n\t<li>";
|
||||
$r .= join("</li>\n\t<li>", $page_links);
|
||||
$r .= "</li>\n</ul>\n";
|
||||
break;
|
||||
default :
|
||||
$r = join("\n", $page_links);
|
||||
break;
|
||||
endswitch;
|
||||
return $r;
|
||||
}
|
||||
?>
|
||||
|
Loading…
Reference in New Issue
Block a user