Switch language

wpseek.com
A WordPress-centric search engine for devs and theme authors




get_page_of_comment [ WordPress Function ]

get_page_of_comment ( $comment_ID, $args = array() )
Parameters:
  • (int) $comment_ID Comment ID.
  • (array) $args Optional args.
Uses:
Returns:
  • (int|null) Comment page number or null on error.
Defined at:



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'] < )
        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'] > && != $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 ( == $oldercoms )
        return 
1;

    
// Divide comments older than this one by comments per page to get this comment's page number
    
return ceil( ( $oldercoms ) / $args['per_page'] );
}
?>

Examples [ wp-snippets.com ]

Google Arama Sonuçlarý

Dahasý ...

Kullanýcý Tartýþmalarý [ wordpress.org ]

- Bulunamadý -

Yeni bir konu yaz ...

0 User Note(s)

Henüz yok. Ýlk sen ol!

Yeni Ekle ...



HTML5 Powered with CSS3 / Styling, Performance & Integration, and Semantics