Changeset 1155

Show
Ignore:
Timestamp:
11/16/07 15:51:19 (10 months ago)
Author:
donncha
Message:

Better pagination, props ktlee, fixes #483

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/wp-admin/wpmu-blogs.php

    r1150 r1155  
    280280        // List blogs 
    281281        default: 
    282                 $start = isset( $_GET['start'] ) ? intval( $_GET['start'] ) : 0
    283                 $num = isset( $_GET['num'] ) ? intval( $_GET['num'] ) : 60; 
     282                $apage = isset( $_GET['apage'] ) ? intval( $_GET['apage'] ) : 1
     283                $num = isset( $_GET['num'] ) ? intval( $_GET['num'] ) : 30; 
    284284                 
    285285                $query = "SELECT * FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' "; 
     
    308308                        $_GET['sortby'] = 'id'; 
    309309                } 
     310                 
    310311                if( $_GET['sortby'] == 'registered' ) { 
    311312                        $query .= ' ORDER BY registered '; 
     
    321322                 
    322323                if ( $_GET['ip_address'] == '' ) 
    323                         $query .= " LIMIT " . intval( $start ) . ", " . intval( $num ); 
     324                        $query .= " LIMIT " . intval( ( $apage - 1 ) * $num) . ", " . intval( $num ); 
    324325                         
    325326                $blog_list = $wpdb->get_results( $query, ARRAY_A );      
    326327                 
    327                 $next = ( count( $blog_list ) < $num ) ? false : true; 
    328                  
     328                if( !empty($_GET['s']) ||  !empty($_GET['blog_id']) || !empty($_GET['ip_address'])) { 
     329                        $total = count($blog_list);      
     330                } else { 
     331                        $total = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' ");      
     332                } 
     333 
    329334                // Pagination 
    330                 $url2 = "order=" . $_GET['order'] . "&amp;sortby=" . $_GET['sortby'] . "&amp;s=" . $_GET['s'] . "&ip_address=" . $_GET['ip_address']; 
    331                 $blog_navigation = ''; 
    332                 if( $start == 0 ) {  
    333                         $blog_navigation .= __('Previous&nbsp;Blogs'); 
    334                 } elseif( $start <= 30 ) {  
    335                         $blog_navigation .= '<a href="wpmu-blogs.php?start=0&amp;' . $url2 . ' ">' . __('Previous&nbsp;Blogs') . '</a>'; 
    336                 } else { 
    337                         $blog_navigation .= '<a href="wpmu-blogs.php?start=' . ( $start - $num ) . '&' . $url2 . '">' . __('Previous&nbsp;Blogs') . '</a>'; 
    338                 }  
    339                 if ( $next ) { 
    340                         $blog_navigation .= '&nbsp;||&nbsp;<a href="wpmu-blogs.php?start=' . ( $start + $num ) . '&' . $url2 . '">' . __('Next&nbsp;Blogs') . '</a>'; 
    341                 } else { 
    342                         $blog_navigation .= '&nbsp;||&nbsp;' . __('Next&nbsp;Blogs'); 
    343                 } 
     335                $url2 = "&order=" . $_GET['order'] . "&amp;sortby=" . $_GET['sortby'] . "&amp;s=" . $_GET['s'] . "&ip_address=" . $_GET['ip_address']; 
     336                $blog_navigation = paginate_links( array( 
     337                        'base' => add_query_arg( 'apage', '%#%' ).$url2, 
     338                        'format' => '', 
     339                        'total' => ceil($total / $num), 
     340                        'current' => $apage 
     341                )); 
    344342                ?> 
    345343                <script type="text/javascript"> 
     
    377375                <h2><?php _e('Blogs') ?></h2> 
    378376                <div style="float:right; padding:0 20px; margin-top:20px;">  
    379                         <h4 style="margin:0 0 4px;"><?php _e('Blog Navigation') ?></h4>  
    380                         <?php echo $blog_navigation; ?> 
     377                        <?php if ( $blog_navigation ) echo "<p class='pagenav'>$blog_navigation</p>"; ?> 
    381378                </div> 
    382379                 
     
    437434                                <tr> 
    438435                                        <?php foreach($posts_columns as $column_id => $column_display_name) : ?> 
    439                                                 <th scope="col"><a href="wpmu-blogs.php?<?php echo $sortby_url ?>&amp;sortby=<?php echo $column_id ?>&amp;<?php if( $_GET['sortby'] == $column_id ) { if( $_GET['order'] == 'DESC' ) { echo "order=ASC&amp;" ; } else { echo "order=DESC&amp;"; } } ?>start=<?php echo $start ?>"><?php echo $column_display_name; ?></a></th> 
     436                                                <th scope="col"><a href="wpmu-blogs.php?<?php echo $sortby_url ?>&amp;sortby=<?php echo $column_id ?>&amp;<?php if( $_GET['sortby'] == $column_id ) { if( $_GET['order'] == 'DESC' ) { echo "order=ASC&amp;" ; } else { echo "order=DESC&amp;"; } } ?>apage=<?php echo $apage ?>"><?php echo $column_display_name; ?></a></th> 
    440437                                        <?php endforeach ?> 
    441438                                </tr> 
     
    595592                 
    596593                <div style="float:right; padding:0 20px; margin-top:20px;">  
    597                         <h4 style="margin:0 0 4px;"><?php _e('Blog Navigation') ?></h4>  
    598                         <?php echo $blog_navigation;?> 
     594                        <?php if ( $blog_navigation ) echo "<p class='pagenav'>$blog_navigation</p>"; ?> 
    599595                </div> 
    600596                <input style="margin:5px 0;" id="check_all2" type="button" class="button" value="<?php _e('Check All') ?>" onclick="check_all_rows()" />