get_page_of_comment [ WordPress Function ]
get_page_of_comment ( $comment_ID, $args = array() )
| Parameters: |
|
| Uses: | |
| Returns: |
|
| Defined at: |
|
Benzer Fonksiyonlar: get_comment, get_comments, get_approved_comments, get_comment_id, get_page_children
Calculate what page number a comment will appear on for comment paging.
Source
<?php
function get_page_of_comment( $comment_ID, $args = array() ) {
global $wpdb;
if ( !$comment = get_comment( $comment_ID ) )
return;
$defaults = array( 'type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '' );
$args = wp_parse_args( $args, $defaults );
if ( '' === $args['per_page'] && get_option('page_comments') )
$args['per_page'] = get_query_var('comments_per_page');
if ( empty($args['per_page']) ) {
$args['per_page'] = 0;
$args['page'] = 0;
}
if ( $args['per_page'] < 1 )
return 1;
if ( '' === $args['max_depth'] ) {
if ( get_option('thread_comments') )
$args['max_depth'] = get_option('thread_comments_depth');
else
$args['max_depth'] = -1;
}
// Find this comment's top level parent if threading is enabled
if ( $args['max_depth'] > 1 && 0 != $comment->comment_parent )
return get_page_of_comment( $comment->comment_parent, $args );
$allowedtypes = array(
'comment' => '',
'pingback' => 'pingback',
'trackback' => 'trackback',
);
$comtypewhere = ( 'all' != $args['type'] && isset($allowedtypes[$args['type']]) ) ? " AND comment_type = '" . $allowedtypes[$args['type']] . "'" : '';
// Count comments older than this one
$oldercoms = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_parent = 0 AND comment_approved = '1' AND comment_date_gmt < '%s'" . $comtypewhere, $comment->comment_post_ID, $comment->comment_date_gmt ) );
// No older comments? Then it's page #1.
if ( 0 == $oldercoms )
return 1;
// Divide comments older than this one by comments per page to get this comment's page number
return ceil( ( $oldercoms + 1 ) / $args['per_page'] );
}
?>
Examples [ wp-snippets.com ]
Google Arama Sonuçlarý
- #8973 (Function get_page_of_comment() returns incorrect page ...
The function get_page_of_comment(), defined in /wp-includes/comment.php for WordPress 2.7, returns wildly incorrect results in cases where the database ...
core.trac.wordpress.org - #13939 (get_page_of_comment returns wrong page number when ...
Initial discussion settings: Enable threaded comments 2 levels deep; 5 top-level comments per page, first page by default; Older comments at top of each page ...
core.trac.wordpress.org - get_page_of_comment | A HitchHackers guide through WordPress
Feb 12, 2011 ... function get_page_of_comment( $comment_ID, $args = array() ) { global $wpdb; if ( !$comment = get_comment( $comment_ID ) ) return; ...
hitchhackerguide.com - get_page_of_comment (WordPress Function) - WPSeek.com
WordPress lookup for get_page_of_comment, a WordPress Function. wpseek. com is a WordPress-centric search tool for developers and theme authors.
wpseek.com