get_page_of_comment() fixes from Viper007Bond. see #7956

git-svn-id: https://develop.svn.wordpress.org/trunk@9377 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2008-10-28 07:17:29 +00:00
parent c33b1bc527
commit 45d0800e30
1 changed files with 10 additions and 5 deletions

View File

@ -529,13 +529,15 @@ function get_comment_pages_count( $comments = null, $per_page = null, $threaded
* @return int|null Comment page number or null on error.
*/
function get_page_of_comment( $comment_ID, $per_page = null, $threaded = null ) {
if ( !$comment = get_comment( $comment_ID ) )
$comment = get_comment( $comment_ID );
if ( !$comment || 1 != $comment->comment_approved )
return;
if ( !get_option('page_comments') )
return 1;
$comments = array_reverse( get_comments( $comment->comment_post_ID ) );
$comments = array_reverse( get_comments( array( 'post_id' => $comment->comment_post_ID ) ) );
if ( null === $per_page )
$per_page = get_option('comments_per_page');
@ -543,10 +545,13 @@ function get_page_of_comment( $comment_ID, $per_page = null, $threaded = null )
if ( null === $threaded )
$threaded = get_option('thread_comments');
// Find this comment's top level parent
if ( $threaded ) {
while ( 0 != $comment->comment_parent )
// Find this comment's top level parent if threading is enabled
if ( $threaded && 0 != $comment->comment_parent ) {
while ( 0 != $comment->comment_parent ) {
$comment = get_comment( $comment->comment_parent );
if ( !$comment || 1 != $comment->comment_approved )
return;
}
}
// Start going through the comments until we find what page number the above top level comment is on