Ticket #483: blog-pagination.diff

File blog-pagination.diff, 4.2 kB (added by ktlee, 10 months ago)
  • wp-admin/wpmu-blogs.php

    old new  
    280280         
    281281        // List blogs 
    282282        default: 
    283                 $start = isset( $_GET['start'] ) ? intval( $_GET['start'] ) : 0
    284                 $num = isset( $_GET['num'] ) ? intval( $_GET['num'] ) : 60; 
     283                $apage = isset( $_GET['apage'] ) ? intval( $_GET['apage'] ) : 1
     284                $num = isset( $_GET['num'] ) ? intval( $_GET['num'] ) : 30; 
    285285                 
    286286                $query = "SELECT * FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' "; 
    287287                 
     
    308308                if( isset( $_GET['sortby'] ) == false ) { 
    309309                        $_GET['sortby'] = 'id'; 
    310310                } 
     311                 
    311312                if( $_GET['sortby'] == 'registered' ) { 
    312313                        $query .= ' ORDER BY registered '; 
    313314                } elseif( $_GET['sortby'] == 'id' ) { 
     
    321322                $query .= ( $_GET['order'] == 'DESC' ) ? 'DESC' : 'ASC'; 
    322323                 
    323324                if ( $_GET['ip_address'] == '' ) 
    324                         $query .= " LIMIT " . intval( $start ) . ", " . intval( $num ); 
     325                        $query .= " LIMIT " . intval( ( $apage - 1 ) * $num) . ", " . intval( $num ); 
    325326                         
    326327                $blog_list = $wpdb->get_results( $query, ARRAY_A );      
    327328                 
    328                 $next = ( count( $blog_list ) < $num ) ? false : true; 
    329                  
    330                 // Pagination 
    331                 $url2 = "order=" . $_GET['order'] . "&amp;sortby=" . $_GET['sortby'] . "&amp;s=" . $_GET['s'] . "&ip_address=" . $_GET['ip_address']; 
    332                 $blog_navigation = ''; 
    333                 if( $start == 0 ) {  
    334                         $blog_navigation .= __('Previous&nbsp;Blogs'); 
    335                 } elseif( $start <= 30 ) {  
    336                         $blog_navigation .= '<a href="wpmu-blogs.php?start=0&amp;' . $url2 . ' ">' . __('Previous&nbsp;Blogs') . '</a>'; 
     329                if( !empty($_GET['s']) ||  !empty($_GET['blog_id']) || !empty($_GET['ip_address'])) { 
     330                        $total = count($blog_list);      
    337331                } else { 
    338                         $blog_navigation .= '<a href="wpmu-blogs.php?start=' . ( $start - $num ) . '&' . $url2 . '">' . __('Previous&nbsp;Blogs') . '</a>'; 
    339                 }  
    340                 if ( $next ) { 
    341                         $blog_navigation .= '&nbsp;||&nbsp;<a href="wpmu-blogs.php?start=' . ( $start + $num ) . '&' . $url2 . '">' . __('Next&nbsp;Blogs') . '</a>'; 
    342                 } else { 
    343                         $blog_navigation .= '&nbsp;||&nbsp;' . __('Next&nbsp;Blogs'); 
     332                        $total = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' ");      
    344333                } 
     334 
     335                // Pagination 
     336                $url2 = "&order=" . $_GET['order'] . "&amp;sortby=" . $_GET['sortby'] . "&amp;s=" . $_GET['s'] . "&ip_address=" . $_GET['ip_address']; 
     337                $blog_navigation = paginate_links( array( 
     338                        'base' => add_query_arg( 'apage', '%#%' ).$url2, 
     339                        'format' => '', 
     340                        'total' => ceil($total / $num), 
     341                        'current' => $apage 
     342                )); 
    345343                ?> 
    346344                <script type="text/javascript"> 
    347345                <!-- 
     
    377375                <div class="wrap"> 
    378376                <h2><?php _e('Blogs') ?></h2> 
    379377                <div style="float:right; padding:0 20px; margin-top:20px;">  
    380                         <h4 style="margin:0 0 4px;"><?php _e('Blog Navigation') ?></h4>  
    381                         <?php echo $blog_navigation; ?> 
     378                        <?php if ( $blog_navigation ) echo "<p class='pagenav'>$blog_navigation</p>"; ?> 
    382379                </div> 
    383380                 
    384381                <form id="searchform" action="wpmu-blogs.php" method="get">  
     
    437434                        <thead> 
    438435                                <tr> 
    439436                                        <?php foreach($posts_columns as $column_id => $column_display_name) : ?> 
    440                                                 <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> 
     437                                                <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> 
    441438                                        <?php endforeach ?> 
    442439                                </tr> 
    443440                        </thead> 
     
    595592                </table> 
    596593                 
    597594                <div style="float:right; padding:0 20px; margin-top:20px;">  
    598                         <h4 style="margin:0 0 4px;"><?php _e('Blog Navigation') ?></h4>  
    599                         <?php echo $blog_navigation;?> 
     595                        <?php if ( $blog_navigation ) echo "<p class='pagenav'>$blog_navigation</p>"; ?> 
    600596                </div> 
    601597                <input style="margin:5px 0;" id="check_all2" type="button" class="button" value="<?php _e('Check All') ?>" onclick="check_all_rows()" />  
    602598