The implementation of displaying the names of all the commentators of an article in WordPress
Editor to share with you how to display the names of all the commentators in an article on WordPress. I hope you will gain a lot after reading this article. Let's discuss it together.
Use the scene, such as in the appropriate place of the article, to show the existing: Shi Zhenxiang, Qin Shousheng, Jiao Hougen, Zhu Yiqun, Xia Jianren, etc., made enthusiastic comments, plus an anchor link to guide the reader to jump to the comment form. Also send an enthusiastic comment.
Add the code to the current theme function template functions.php:
Function get_comment_authors_list ($id = 0, $sep =',') {$post_id = $id? $id: get_the_ID (); if ($post_id) {$comments = get_comments (array ('post_id' = > $post_id,'status' = >' approve','type' = > 'comment',)); $names = array (); foreach ($comments as $comment) {$name = $comment- > comment_author If ($comment- > user_id) {$user = get_userdata ($comment- > user_id); $name = $user? $user- > display_name: $name;} $arr = explode ('', trim ($name)); if (! Empty ($arr [0]) & &! In_array ($arr [0], $names) {$names [] = $arr [0];}} unset ($comments); $sep = $sep? $sep:','; return implode ($sep, $names);}} add_shortcode ('comment_authors_list',' comment_authors_list_shortcode'); function comment_authors_list_shortcode ($atts = array ()) {$atts = shortcode_atts (array ('post_id' = > quota sep' = >',), $atts) Return get_comment_authors_list ($atts ['post_id'], $atts [' list_sep']);}
How to use it:
1. Call ID: 123The names of all the commentators of the article
Use in templates:
Add a short code to the article:
[comment_authors_list post_id= "123" /]
Second, call the names of all commentators of the current article, similar to the above, but remove the article ID, which is suitable to be placed in the article body template.
Use in templat
Add a short code to the article:
[comment_authors_list /] after reading this article, I believe you have some understanding of how to display the names of all commentators in an WordPress article. If you want to know more about it, welcome to follow the industry information channel. Thank you for reading!