Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * WordPress Pagination
- * If you need pagination for a custom query, insert it into the function as a parameter.
- *
- * Modified version of the snippet found here: http://wp-snippets.com/pagination-without-plugin/
- *
- * @version v1.00a
- * @global $wp_query
- * @param object $query optional custom query
- * @return void
- * @author Kenth Hagström <info@kenthhagstrom.se>
- * @link http://kenthhagstrom.se
- */
- function keha76_pagination( $query = '' ) {
- if ( ! is_object( $query ) ) {
- global $wp_query;
- $query = $wp_query;
- }
- $current = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
- if ( get_option('permalink_structure') ) {
- $format = 'page/%#%';
- } else {
- $format = '?paged=%#%';
- if ( ! is_home() )
- $format = '&paged=%#%';
- }
- if ( $query->max_num_pages > 1 ) {
- $defaults = array(
- 'base' => str_replace( PHP_INT_MAX, '%#%', esc_url( get_pagenum_link() ) ),
- 'format' => $format,
- 'total' => $query->max_num_pages,
- 'current' => max( 1, $current ),
- 'show_all' => false,
- 'end_size' => 1,
- 'mid_size' => 3,
- 'prev_next' => true,
- 'prev_text' => __( 'Prev', 'kah76' ),
- 'next_text' => __( 'Next', 'kah76' ),
- 'type' => 'plain',
- 'add_args' => false,
- 'add_fragment' => ''
- );
- $args = wp_parse_args( apply_filters( 'keha76_pagination_parameters', $defaults ) );
- echo paginate_links( $args );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement