How WordPress calls the list of the latest comments

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

Function code:

<?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>

usage method:

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.

Related Article
how to automatically add tag links to the article

Today, I'd like to share a WordPress SEO optimization tip, which can realize the automatic addition of keyword tags in Read more

WordPress displays the registration time of the login user in the frontend

When using WordPress to build a website, some users want to display the user registration time in the frontend, but Read more

WordPress adds the number of SQL queries at the bottom

An excellent woodpress theme is definitely that the less SQL consulting is used, the better. How can we see how Read more

Some WordPress articles can be seen after comments / replies

If we want to hide part of the content of the article and need the user's comments and replies to Read more

Leave a Reply

Your email address will not be published. Required fields are marked *

*
To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-spam image