Changeset 9808 for trunk/wp-includes/comment.php
- Timestamp:
- 11/20/2008 06:41:55 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/comment.php
r9782 r9808 549 549 * 550 550 * @param int $comment_ID Comment ID. 551 * @param int $per_page Optional comments per page.551 * @param array $args Optional args. 552 552 * @return int|null Comment page number or null on error. 553 553 */ 554 function get_page_of_comment( $comment_ID, $ per_page = null, $threaded = null) {554 function get_page_of_comment( $comment_ID, $args = array() ) { 555 555 global $wpdb; 556 556 … … 558 558 return; 559 559 560 if ( !get_option('page_comments') ) 560 $defaults = array( 'type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '' ); 561 $args = wp_parse_args( $args, $defaults ); 562 563 if ( '' === $args['per_page'] && get_option('page_comments') ) 564 $args['per_page'] = get_query_var('comments_per_page'); 565 if ( empty($args['per_page']) ) { 566 $args['per_page'] = 0; 567 $args['page'] = 0; 568 } 569 if ( $args['per_page'] < 1 ) 561 570 return 1; 562 571 563 if ( null === $per_page ) 564 $per_page = get_option('comments_per_page'); 565 566 if ( null === $threaded ) 567 $threaded = get_option('thread_comments'); 572 if ( '' === $args['max_depth'] ) { 573 if ( get_option('thread_comments') ) 574 $args['max_depth'] = get_option('thread_comments_depth'); 575 else 576 $args['max_depth'] = -1; 577 } 568 578 569 579 // Find this comment's top level parent if threading is enabled 570 if ( $threaded && 0 != $comment->comment_parent ) 571 return get_page_of_comment( $comment->comment_parent, $per_page, $threaded ); 580 if ( $args['max_depth'] > 1 && 0 != $comment->comment_parent ) 581 return get_page_of_comment( $comment->comment_parent, $args ); 582 583 $allowedtypes = array( 584 'comment' => '', 585 'pingback' => 'pingback', 586 'trackback' => 'trackback', 587 ); 588 589 $comtypewhere = ( 'all' != $args['type'] && isset($allowedtypes[$args['type']]) ) ? " AND comment_type = '" . $allowedtypes[$args['type']] . "'" : ''; 572 590 573 591 // Count comments older than this one 574 $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 ) );592 $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'" . $comtypewhere, $comment->comment_post_ID, $comment->comment_date_gmt ) ); 575 593 576 594 // No older comments? Then it's page #1. … … 579 597 580 598 // Divide comments older than this one by comments per page to get this comment's page number 581 return ceil( ( $oldercoms + 1 ) / $ per_page);599 return ceil( ( $oldercoms + 1 ) / $args['per_page'] ); 582 600 } 583 601
Note: See TracChangeset
for help on using the changeset viewer.