Ticket #7956: 7956.6.patch
File 7956.6.patch, 4.6 KB (added by , 16 years ago) |
---|
-
wp-includes/comment-template.php
435 435 * @uses $comment 436 436 * 437 437 * @param object|string|int $comment Comment to retrieve. 438 * @param string|int $page The comment's page if known. Optional. Avoids extra database query. 438 439 * @return string The permalink to the current comment 439 440 */ 440 function get_comment_link( $comment = null) {441 function get_comment_link( $comment = null, $page = null ) { 441 442 global $wp_rewrite; 442 443 443 444 $comment = get_comment($comment); 444 445 445 446 if ( get_option('page_comments') ) { 446 $page = get_page_of_comment( $comment->comment_ID );447 $page = (int) ( null !== $page ) ? $page : get_page_of_comment( $comment->comment_ID ); 447 448 448 449 if ( $wp_rewrite->using_permalinks() ) 449 450 return user_trailingslashit( trailingslashit( get_permalink( $comment->comment_post_ID ) ) . "comment-page-$page", 'comment' ) . '#comment-' . $comment->comment_ID; … … 1150 1151 <br /> 1151 1152 <?php endif; ?> 1152 1153 1153 <div class="comment-meta commentmetadata"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>"><?php printf(__('%1$s at %2$s'), get_comment_date('F jS, Y'), get_comment_time()) ?></a><?php edit_comment_link('edit',' ','') ?></div>1154 <div class="comment-meta commentmetadata"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID, $page ) ) ?>"><?php printf(__('%1$s at %2$s'), get_comment_date('F jS, Y'), get_comment_time()) ?></a><?php edit_comment_link('edit',' ','') ?></div> 1154 1155 1155 1156 <?php comment_text() ?> 1156 1157 -
wp-includes/comment.php
536 536 * @return int|null Comment page number or null on error. 537 537 */ 538 538 function get_page_of_comment( $comment_ID, $per_page = null, $threaded = null ) { 539 global $wpdb; 540 539 541 if ( !$comment = get_comment( $comment_ID ) ) 540 542 return; 541 543 … … 552 554 if ( $threaded && 0 != $comment->comment_parent ) 553 555 return get_page_of_comment( $comment->comment_parent, $per_page, $threaded ); 554 556 555 $comments = get_comments( array( 'post_id' => $comment->comment_post_ID, 'order' => 'ASC' ) ); 557 // Count comments older than this one 558 $oldercoms = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_parent = 0 AND comment_date_gmt < '%s'", $comment->comment_post_ID, $comment->comment_date_gmt ) ); 556 559 557 // Start going through the comments until we find what page number the above top level comment is on 558 $page = 1; 559 $comthispage = 0; 560 foreach ( $comments as $com ) { 561 if ( $threaded && 0 != $com->comment_parent ) 562 continue; 560 // No older comments? Then it's page #1. 561 if ( 0 == $oldercoms ) 562 return 1; 563 563 564 if ( $com->comment_ID == $comment->comment_ID ) 565 return $page; 566 567 $comthispage++; 568 569 if ( $comthispage >= $per_page ) { 570 $page++; 571 $comthispage = 0; 572 } 573 } 564 // Divide comments older than this one by comments per page to get this comment's page number 565 return ceil( ( $oldercoms + 1 ) / $per_page ); 574 566 } 575 567 576 568 /** -
wp-includes/widgets.php
1387 1387 $number = 15; 1388 1388 1389 1389 if ( !$comments = wp_cache_get( 'recent_comments', 'widget' ) ) { 1390 $comments = $wpdb->get_results("SELECT comment_author, comment_author_url, comment_ID, comment_post_IDFROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT $number");1390 $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT $number"); 1391 1391 wp_cache_add( 'recent_comments', $comments, 'widget' ); 1392 1392 } 1393 1393 ?> … … 1396 1396 <?php echo $before_title . $title . $after_title; ?> 1397 1397 <ul id="recentcomments"><?php 1398 1398 if ( $comments ) : foreach ( (array) $comments as $comment) : 1399 echo '<li class="recentcomments">' . sprintf(__('%1$s on %2$s'), get_comment_author_link(), '<a href="'. get_ permalink($comment->comment_post_ID) . '#comment-' . $comment->comment_ID. '">' . get_the_title($comment->comment_post_ID) . '</a>') . '</li>';1399 echo '<li class="recentcomments">' . sprintf(__('%1$s on %2$s'), get_comment_author_link(), '<a href="'. get_comment_link($comment->comment_ID) . '">' . get_the_title($comment->comment_post_ID) . '</a>') . '</li>'; 1400 1400 endforeach; endif;?></ul> 1401 1401 <?php echo $after_widget; ?> 1402 1402 <?php