Skip to content

Instantly share code, notes, and snippets.

@mahmudinm
Forked from ediamin/bootstrap-pagination.php
Created October 15, 2018 06:43
Show Gist options
  • Select an option

  • Save mahmudinm/26d0b3929a9b5debe41c6100e1652aa9 to your computer and use it in GitHub Desktop.

Select an option

Save mahmudinm/26d0b3929a9b5debe41c6100e1652aa9 to your computer and use it in GitHub Desktop.

Revisions

  1. @ediamin ediamin renamed this gist Jul 5, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. @ediamin ediamin created this gist Jul 5, 2015.
    39 changes: 39 additions & 0 deletions bootstrap-pagination
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    /*
    * custom pagination with bootstrap .pagination class
    * source: http://www.ordinarycoder.com/paginate_links-class-ul-li-bootstrap/
    */
    function bootstrap_pagination( $echo = true ) {
    global $wp_query;

    $big = 999999999; // need an unlikely integer

    $pages = paginate_links( array(
    'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
    'format' => '?paged=%#%',
    'current' => max( 1, get_query_var('paged') ),
    'total' => $wp_query->max_num_pages,
    'type' => 'array',
    'prev_next' => true,
    'prev_text' => __('« Prev'),
    'next_text' => __('Next »'),
    )
    );

    if( is_array( $pages ) ) {
    $paged = ( get_query_var('paged') == 0 ) ? 1 : get_query_var('paged');

    $pagination = '<ul class="pagination">';

    foreach ( $pages as $page ) {
    $pagination .= "<li>$page</li>";
    }

    $pagination .= '</ul>';

    if ( $echo ) {
    echo $pagination;
    } else {
    return $pagination;
    }
    }
    }