Changeset 4479

Show
Ignore:
Timestamp:
11/18/06 06:52:01 (2 years ago)
Author:
matt
Message:

Paging for comments

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/wp-admin/edit-comments.php

    r4478 r4479  
    8484        ORDER BY comment_date DESC"); 
    8585} else { 
    86     if ( isset($_GET['offset']) ) 
    87         $offset = (int) $_GET['offset'] * 20
     86    if ( isset( $_GET['apage'] ) ) 
     87        $page = (int) $_GET['apage']
    8888    else 
    89         $offset = 0; 
    90  
    91     $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_approved = '0' OR comment_approved = '1' ORDER BY comment_date DESC LIMIT $offset,20"); 
    92 
     89        $page = 1; 
     90    $start = $offset = ( $page - 1 ) * 20; 
     91    $end = $start + 20; 
     92 
     93    $comments = $wpdb->get_results( "SELECT * FROM $wpdb->comments WHERE comment_approved = '0' OR comment_approved = '1' ORDER BY comment_date DESC LIMIT $start, $end" ); 
     94    $total = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '0' OR comment_approved = '1'" ); 
     95
     96?> 
     97<?php if ( $total > 20 ) { 
     98$total_pages = ceil( $total / 20 ); 
     99$r = ''; 
     100if ( 1 < $page ) { 
     101    $args['apage'] = ( 1 == $page - 1 ) ? FALSE : $page - 1; 
     102    $r .=  '<a class="prev" href="' . add_query_arg( $args ) . '">&laquo; '. __('Previous Page') .'</a>' . "\n"; 
     103
     104if ( ( $total_pages = ceil( $total / 20 ) ) > 1 ) { 
     105    for ( $page_num = 1; $page_num <= $total_pages; $page_num++ ) : 
     106        if ( $page == $page_num ) : 
     107            $r .=  "<span>$page_num</span>\n"; 
     108        else : 
     109            $p = false; 
     110            if ( $page_num < 3 || ( $page_num >= $page - 3 && $page_num <= $page + 3 ) || $page_num > $total_pages - 3 ) : 
     111                $args['apage'] = ( 1 == $page_num ) ? FALSE : $page_num; 
     112                $r .= '<a class="page-numbers" href="' . add_query_arg($args) . '">' . ( $page_num ) . "</a>\n"; 
     113                $in = true; 
     114            elseif ( $in == true ) : 
     115                $r .= "...\n"; 
     116                $in = false; 
     117            endif; 
     118        endif; 
     119    endfor; 
     120
     121if ( ( $page ) * 20 < $total || -1 == $total ) { 
     122    $args['apage'] = $page + 1; 
     123    $r .=  '<a class="next" href="' . add_query_arg($args) . '">'. __('Next Page') .' &raquo;</a>' . "\n"; 
     124
     125echo "<p>$r</p>"; 
     126?> 
     127 
     128<?php } ?> 
     129 
     130<?php 
    93131if ('view' == $mode) { 
    94132    if ($comments) { 
    95         if ($offset) 
    96             $start = " start='$offset'"; 
    97         else 
    98            $start = ''
     133?> 
     134<?php 
     135$offset = $offset + 1; 
     136$start = " start='$offset'"
    99137 
    100138        echo "<ol id='the-comment-list' class='commentlist' $start>"; 
     
    204242} 
    205243    ?> 
     244<?php if ( $total > 20 ) { 
     245$total_pages = ceil( $total / 20 ); 
     246$r = ''; 
     247if ( 1 < $page ) { 
     248    $args['apage'] = ( 1 == $page - 1 ) ? FALSE : $page - 1; 
     249    $r .=  '<a class="prev" href="' . add_query_arg( $args ) . '">&laquo; '. __('Previous Page') .'</a>' . "\n"; 
     250} 
     251if ( ( $total_pages = ceil( $total / 20 ) ) > 1 ) { 
     252    for ( $page_num = 1; $page_num <= $total_pages; $page_num++ ) : 
     253        if ( $page == $page_num ) : 
     254            $r .=  "<span>$page_num</span>\n"; 
     255        else : 
     256            $p = false; 
     257            if ( $page_num < 3 || ( $page_num >= $page - 3 && $page_num <= $page + 3 ) || $page_num > $total_pages - 3 ) : 
     258                $args['apage'] = ( 1 == $page_num ) ? FALSE : $page_num; 
     259                $r .= '<a class="page-numbers" href="' . add_query_arg($args) . '">' . ( $page_num ) . "</a>\n"; 
     260                $in = true; 
     261            elseif ( $in == true ) : 
     262                $r .= "...\n"; 
     263                $in = false; 
     264            endif; 
     265        endif; 
     266    endfor; 
     267} 
     268if ( ( $page ) * 20 < $total || -1 == $total ) { 
     269    $args['apage'] = $page + 1; 
     270    $r .=  '<a class="next" href="' . add_query_arg($args) . '">'. __('Next Page') .' &raquo;</a>' . "\n"; 
     271} 
     272echo "<p>$r</p>"; 
     273?> 
     274 
     275<?php } ?> 
    206276 
    207277</div>