Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The implementation of displaying the names of all the commentators of an article in WordPress

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report