Вопрос

Мне нужно отобразить комментарии, начиная со второго, пропустив первое. С сообщениями я сделал это, используя «смещение», но я не могу найти что -то подобное для комментариев. Поскольку я использую резьбовые комментарии, должен начинаться со второго комментария, который не является ребенком (только родители комментарии). Я использую wp_list_comments с обратным вызовом.

EDIT2: это фактический код comments.php, после ответов:

      <?php 
$i = 2;
if ( have_comments() ) : 
if ( $i > 1 ) :
?>
    <div id="comments">
    <h3 id="comments-title" class="color-<?php $category = get_the_category(); echo $category[0]->cat_name;?>">
</h3>


    <?php 

     global $wp_query; 
     $comments_arr = $wp_query->comments; 
     $comments_arr = sort( $comments_arr); 
     $comments_arr = array_pop( $comments_arr );
     $comments_arr = usort($comment_arr, 'comment_comparator');                 
     wp_list_comments('callback=gtcn_basic_callback', $comments_arr); 

    ?>


    <?php
    $i++; // count up
    endif; // If $i > 1
    else : if ( ! comments_open() ) : ?>
            <p><?php _e( 'Comments are closed.' ); ?></p>

    <?php 
      endif; // end ! comments_open() 
endif; // end have_comments()  ?>
</div>
<?php comment_form(); ?>

Результат: комментарии больше не заказаны Karma (функция Comment_comparator), и первый комментарий (комментарий с Top Karma, который я хочу скрыть) все еще отображается.

Это было полезно?

Решение

<?php 
global $wp_query, $post; 
$comments_arr = $wp_query->comments; 
$comments_arr = sort( $comments_arr); 
$comments_arr = array_pop( $comments_arr );
$comments_arr = usort($comment_arr, 'comment_comparator');

$comment_count = get_comment_count($post->ID);

 ?>
<h3 id="comments-title"><?php
    printf(
    _n( 'One Response to %2$s', '%1$s Responses to %2$s', get_comments_number(), 'YOUR_THEMES_TEXTDOMAIN' ),
    number_format_i18n( get_comments_number() ),
    '<em>' . get_the_title() . '</em>' 
);
?></h3>
if ( have_comments() ) : 
?><ul class="commentlist"><?php
for ( $i = 0; $i < $comment_count; $i++ )
{
    // do stuff: 
        // This shows you everything you got inside the comments array
        // Call it like this: echo $comments_arr[$i]['comment_author'];
        var_dump( $comments_arr[$i] ); 
    // end do stuff
} // endforeach;
?></ul><?php

elseif ('open' == $post->comment_status) :
    // If there are no comments, but status = open
    ?><p class="nocomments"><?php _e( 'No Comments.', 'YOUR_THEMES_TEXTDOMAIN' ); ?></p><?php
endif; // If $i > 1

else : // or, if comments are not allowed:
    if ( ! comments_open() ) : 
    ?>
        <p class="nocomments"><?php _e( 'Comments are closed.', 'YOUR_THEMES_TEXTDOMAIN' ); ?></p>
    <?php 
    endif; // end ! comments_open() 
endif; // end have_comments() 
?>

Ad yourtemplop:

Нет необходимости $counter = 2; (называется никуда).

Если вы уже получили свой $comments_arr, почему бы не просто:

$comments_arr = sort( $comments_arr); 
$comments_arr = array_pop( $comments_arr ); 
$comments_arr = usort( $comments_arr );

ИЛИ ЖЕ

$comments_arr = unset( $comments_arr[0] ); 
$comments_arr = usort( $comments_arr );
Лицензировано под: CC-BY-SA с атрибуция
Не связан с wordpress.stackexchange
scroll top