Support » Developing with WordPress » Comment callback function – pass $args

  • Resolved astatine85

    (@astatine85)


    In this page https://codex.wordpress.org/Function_Reference/wp_list_comments the following function is used as a comment callback function.

    <ul class="commentlist">
    <?php wp_list_comments( 'type=comment&callback=mytheme_comment' ); ?>
    </ul>

    And the function is defined like this.

    function mytheme_comment($comment, $args, $depth) {
        if ( 'div' === $args['style'] ) {
            $tag       = 'div';
            $add_below = 'comment';
        } else {
            $tag       = 'li';
            $add_below = 'div-comment';
        }?>
        <<?php echo $tag; ?> <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ); ?> id="comment-<?php comment_ID() ?>"><?php 
        if ( 'div' != $args['style'] ) { ?>
            <div id="div-comment-<?php comment_ID() ?>" class="comment-body"><?php
        } ?>
            <div class="comment-author vcard"><?php 
                if ( $args['avatar_size'] != 0 ) {
                    echo get_avatar( $comment, $args['avatar_size'] ); 
                } 
                printf( __( '<cite class="fn">%s</cite> <span class="says">says:</span>' ), get_comment_author_link() ); ?>
            </div><?php 
            if ( $comment->comment_approved == '0' ) { ?>
                <em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.' ); ?><br/><?php 
            } ?>
            <div class="comment-meta commentmetadata">
                comment_ID ) ); ?>"><?php
                    /* translators: 1: date, 2: time */
                    printf( 
                        __('%1$s at %2$s'), 
                        get_comment_date(),  
                        get_comment_time() 
                    ); ?>
                <?php 
                edit_comment_link( __( '(Edit)' ), '  ', '' ); ?>
            </div>
    
            <?php comment_text(); ?>
    
            <div class="reply"><?php 
                    comment_reply_link( 
                        array_merge( 
                            $args, 
                            array( 
                                'add_below' => $add_below, 
                                'depth'     => $depth, 
                                'max_depth' => $args['max_depth'] 
                            ) 
                        ) 
                    ); ?>
            </div><?php 
        if ( 'div' != $args['style'] ) : ?>
            </div><?php 
        endif;
    }
    

    My question is, how do I pass arguments to this function like this:

    wp_list_comments( array(
       'style'       => 'ol',
       'short_ping'  => true,
       'avatar_size' => 24,
    ) );
    
Viewing 1 replies (of 1 total)
  • Thread Starter astatine85

    (@astatine85)

    OK figured it out for anyone needing help.

    wp_list_comments( array (
       'style' => 'ol',
       'short_ping' => 'true',
       'avatar_size' => 24,
       'callback' => 'mytheme_comment'
    ))
    
Viewing 1 replies (of 1 total)
  • The topic ‘Comment callback function – pass $args’ is closed to new replies.