Calling the list of the latest comments is the same as calling the hot comments on the website. This function is different from calling the comments. It just gets the latest comments and sorts them according to the time of the latest comment, so that visitors can read them selectively. The final effect is similar
<?php /* * WordPressHow to call the list of recently commented articles */ $pop = $wpdb->get_results("SELECT DISTINCT comment_post_ID FROM $wpdb->comments WHERE comment_approved = 1 AND comment_post_ID NOT IN ( SELECT ID FROM $wpdb->posts WHERE post_type != 'post' OR post_status != 'publish' OR post_password != '' ) ORDER BY comment_date_gmt DESC LIMIT 10"); ?>//10 by10Data <ul> <?php foreach($pop as $post) : ?> <li><a href="<?php echo get_permalink($post->comment_post_ID); ?>" rel="external nofollow" ><?php echo get_the_title($post->comment_post_ID); ?></a></li> <?php endforeach; ?> </ul>
Put the above code in the sidebar.php 、 single.php We need to call the appropriate position of the latest comment list to achieve the corresponding effect.