• Resolved v123shine

    (@v123shine)


    Good day,

    I’m using this code for display top 10 recent comments from custom post type “book“.

    <ul>
    	<?php
    		$args = array(
    			'post_type' => 'ask',
    			'number' 	=> '10',
    			'orderby'	=> 'date',
    			'order' 	=> 'DESC'
    		);
    	$comments = get_comments( $args );
    	foreach($comments as $bw_comment): ?>
    		<li><a href="<?php echo get_permalink($bw_comment->comment_post_ID); ?>"><?php echo get_the_title($bw_comment->comment_post_ID); ?></a></li>
    	<?php endforeach;?>
    </ul>

    Everything work fine. But the problem is, if one post have so many replied. And top 10 recent comments can contains only one post. This is very bad for visual.

    Screenshot: https://s32.postimg.org/5sc7i45p1/same.jpg

    Is that possible 1 post only display once in recent post??

    Thanks.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter v123shine

    (@v123shine)

    Update: This is the right question.

    Is that possible 1 post only display once in recent comment??

    Hello v123shine,
    Please add this code in your theme functions.php file

    $args = array(
      'post_type'       =>  'ask',
      'number'  => '10',
      'orderby' => 'date',
      'order'  => 'DESC'
    );
    $comments = get_comments( $args );
    $post_comment = array();
    foreach($comments as $bw_comment):
     if (!in_array($bw_comment -> comment_post_ID, $post_comment)):
      ?><li><a href="<?php echo get_permalink($bw_comment->comment_post_ID); ?>"><?php echo get_the_title($bw_comment->comment_post_ID); ?></a></li><?php
      $post_comment[] = $bw_comment -> comment_post_ID;
     endif;
    endforeach;

    This code will display 1 post only display once in recent comment.
    Hope it will help you .
    Thanks

    Thread Starter v123shine

    (@v123shine)

    Dear Cedcommerce, thank you… thank you very much for your kindly help ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Display Recent Comment One Time’ is closed to new replies.