WordPress

personalizacja – Niestandardowa lista komentarzy, odpowiednia głębokość

  • 14 kwietnia, 2014
  • 3 min read
personalizacja – Niestandardowa lista komentarzy, odpowiednia głębokość


Stworzyłem niestandardową funkcję comments_list(), działa dobrze, jedynym problemem jest wyświetlanie komentarzy podrzędnych w nadrzędnym div. Działa dobrze z pierwszym i drugim poziomem głębokości, ale nie z innymi.

to jest mój kod:

/* -----------------------------------------------------------------------------
 * Comments custom functions
 * -------------------------------------------------------------------------- */
//Custom comments lst
function t_one_comments_list( $comment, $args, $depth ) {
    $GLOBALS['comment'] = $comment;
    switch( $comment->comment_type ) :
        case 'pingback' :
        case 'trackback' : ?>
        <li <?php comment_class(); ?> id="comment<?php comment_ID(); ?>">
            <div class="back-link"><?php comment_author_link(); ?></div>
    <?php
            break;
        default :
    ?>
</li>
<?php if ($depth == 1) {?>
   <div <?php comment_class('media'); ?> id="comment-<?php comment_ID(); ?>">
        <?php if ($comment->comment_approved == '0') : ?>
            <p><?php _e('Your comment is awaiting moderation.', 't_one') ?></p>
        <?php endif; ?>
            <div class="pull-left">
                <?php echo get_avatar( $comment, 100 ); ?>
            </div>
            <div class="media-body">
                <div class="well">
                    <div class="media-heading">
                        <strong><?php comment_author(); ?></strong>&nbsp; <small><?php printf( __('%1$s', 't_one'), get_comment_date()) ?></small>
                        <?php edit_comment_link(__(' Edit', 't_one'), ' ', '' ); ?>
                        <?php comment_reply_link( array_merge( $args, array( 
                                'reply_text' => __( '<i class="fa fa-repeat"></i>Reply', 't_one' ),
                                'depth' => $depth,
                                'max_depth' => $args['max_depth'] 
                                ) ) ); ?>
                    </div>
                    <p><?php comment_text() ?></p>
            </div>
            <?php if ( $depth + 1) { ?>
            <div <?php comment_class('media'); ?> id="comment-<?php comment_ID(); ?>">
        <?php if ($comment->comment_approved == '0') : ?>
            <p><?php _e('Your comment is awaiting moderation.', 't_one') ?></p>
        <?php endif; ?>
            <div class="pull-left">
                <?php echo get_avatar( $comment, 100 ); ?>
            </div>
            <div class="media-body">
                <div class="well">
                    <div class="media-heading">
                        <strong><?php comment_author(); ?></strong>&nbsp; <small><?php printf( __('%1$s', 't_one'), get_comment_date()) ?></small>
                        <?php edit_comment_link(__(' Edit', 't_one'), ' ', '' ); ?>
                        <?php comment_reply_link( array_merge( $args, array( 
                                'reply_text' => __( '<i class="fa fa-repeat"></i>Reply', 't_one' ),
                                'depth' => $depth,
                                'max_depth' => $args['max_depth'] 
                                ) ) ); ?>
                    </div>
                    <p><?php comment_text() ?></p>
            </div>
            </div>

            <?php } ?>
            </div>
         <?php } ?>
    <?php // End the default styling of comment
        break;
    endswitch;
}

Jaki jest właściwy sposób używania $ głębokość?

Warto przeczytać!  Stefano Cassone – Wiadomości WordPress

Z góry dziękuję!


Źródło