Paging for comments
git-svn-id: http://svn.automattic.com/wordpress/trunk@4479 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
07126127e6
commit
2ef26430ec
|
@ -83,19 +83,57 @@ if (isset($_GET['s'])) {
|
||||||
comment_approved != 'spam'
|
comment_approved != 'spam'
|
||||||
ORDER BY comment_date DESC");
|
ORDER BY comment_date DESC");
|
||||||
} else {
|
} else {
|
||||||
if ( isset($_GET['offset']) )
|
if ( isset( $_GET['apage'] ) )
|
||||||
$offset = (int) $_GET['offset'] * 20;
|
$page = (int) $_GET['apage'];
|
||||||
else
|
else
|
||||||
$offset = 0;
|
$page = 1;
|
||||||
|
$start = $offset = ( $page - 1 ) * 20;
|
||||||
|
$end = $start + 20;
|
||||||
|
|
||||||
$comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_approved = '0' OR comment_approved = '1' ORDER BY comment_date DESC LIMIT $offset,20");
|
$comments = $wpdb->get_results( "SELECT * FROM $wpdb->comments WHERE comment_approved = '0' OR comment_approved = '1' ORDER BY comment_date DESC LIMIT $start, $end" );
|
||||||
|
$total = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '0' OR comment_approved = '1'" );
|
||||||
}
|
}
|
||||||
|
?>
|
||||||
|
<?php if ( $total > 20 ) {
|
||||||
|
$total_pages = ceil( $total / 20 );
|
||||||
|
$r = '';
|
||||||
|
if ( 1 < $page ) {
|
||||||
|
$args['apage'] = ( 1 == $page - 1 ) ? FALSE : $page - 1;
|
||||||
|
$r .= '<a class="prev" href="' . add_query_arg( $args ) . '">« '. __('Previous Page') .'</a>' . "\n";
|
||||||
|
}
|
||||||
|
if ( ( $total_pages = ceil( $total / 20 ) ) > 1 ) {
|
||||||
|
for ( $page_num = 1; $page_num <= $total_pages; $page_num++ ) :
|
||||||
|
if ( $page == $page_num ) :
|
||||||
|
$r .= "<span>$page_num</span>\n";
|
||||||
|
else :
|
||||||
|
$p = false;
|
||||||
|
if ( $page_num < 3 || ( $page_num >= $page - 3 && $page_num <= $page + 3 ) || $page_num > $total_pages - 3 ) :
|
||||||
|
$args['apage'] = ( 1 == $page_num ) ? FALSE : $page_num;
|
||||||
|
$r .= '<a class="page-numbers" href="' . add_query_arg($args) . '">' . ( $page_num ) . "</a>\n";
|
||||||
|
$in = true;
|
||||||
|
elseif ( $in == true ) :
|
||||||
|
$r .= "...\n";
|
||||||
|
$in = false;
|
||||||
|
endif;
|
||||||
|
endif;
|
||||||
|
endfor;
|
||||||
|
}
|
||||||
|
if ( ( $page ) * 20 < $total || -1 == $total ) {
|
||||||
|
$args['apage'] = $page + 1;
|
||||||
|
$r .= '<a class="next" href="' . add_query_arg($args) . '">'. __('Next Page') .' »</a>' . "\n";
|
||||||
|
}
|
||||||
|
echo "<p>$r</p>";
|
||||||
|
?>
|
||||||
|
|
||||||
|
<?php } ?>
|
||||||
|
|
||||||
|
<?php
|
||||||
if ('view' == $mode) {
|
if ('view' == $mode) {
|
||||||
if ($comments) {
|
if ($comments) {
|
||||||
if ($offset)
|
?>
|
||||||
$start = " start='$offset'";
|
<?php
|
||||||
else
|
$offset = $offset + 1;
|
||||||
$start = '';
|
$start = " start='$offset'";
|
||||||
|
|
||||||
echo "<ol id='the-comment-list' class='commentlist' $start>";
|
echo "<ol id='the-comment-list' class='commentlist' $start>";
|
||||||
$i = 0;
|
$i = 0;
|
||||||
|
@ -203,6 +241,38 @@ $post_title = ('' == $post_title) ? "# $comment->comment_post_ID" : $post_title;
|
||||||
} // end if ($comments)
|
} // end if ($comments)
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
<?php if ( $total > 20 ) {
|
||||||
|
$total_pages = ceil( $total / 20 );
|
||||||
|
$r = '';
|
||||||
|
if ( 1 < $page ) {
|
||||||
|
$args['apage'] = ( 1 == $page - 1 ) ? FALSE : $page - 1;
|
||||||
|
$r .= '<a class="prev" href="' . add_query_arg( $args ) . '">« '. __('Previous Page') .'</a>' . "\n";
|
||||||
|
}
|
||||||
|
if ( ( $total_pages = ceil( $total / 20 ) ) > 1 ) {
|
||||||
|
for ( $page_num = 1; $page_num <= $total_pages; $page_num++ ) :
|
||||||
|
if ( $page == $page_num ) :
|
||||||
|
$r .= "<span>$page_num</span>\n";
|
||||||
|
else :
|
||||||
|
$p = false;
|
||||||
|
if ( $page_num < 3 || ( $page_num >= $page - 3 && $page_num <= $page + 3 ) || $page_num > $total_pages - 3 ) :
|
||||||
|
$args['apage'] = ( 1 == $page_num ) ? FALSE : $page_num;
|
||||||
|
$r .= '<a class="page-numbers" href="' . add_query_arg($args) . '">' . ( $page_num ) . "</a>\n";
|
||||||
|
$in = true;
|
||||||
|
elseif ( $in == true ) :
|
||||||
|
$r .= "...\n";
|
||||||
|
$in = false;
|
||||||
|
endif;
|
||||||
|
endif;
|
||||||
|
endfor;
|
||||||
|
}
|
||||||
|
if ( ( $page ) * 20 < $total || -1 == $total ) {
|
||||||
|
$args['apage'] = $page + 1;
|
||||||
|
$r .= '<a class="next" href="' . add_query_arg($args) . '">'. __('Next Page') .' »</a>' . "\n";
|
||||||
|
}
|
||||||
|
echo "<p>$r</p>";
|
||||||
|
?>
|
||||||
|
|
||||||
|
<?php } ?>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue