{"id":31814,"date":"2024-11-25T17:32:53","date_gmt":"2024-11-25T09:32:53","guid":{"rendered":"https:\/\/fwq.ai\/blog\/31814\/"},"modified":"2024-11-25T17:32:53","modified_gmt":"2024-11-25T09:32:53","slug":"%e5%a6%82%e4%bd%95%e6%98%be%e7%a4%bawordpress%e6%9f%90%e4%b8%aa%e6%96%87%e7%ab%a0%e6%89%80%e6%9c%89%e8%af%84%e8%ae%ba%e8%80%85%e5%90%8d%e7%a7%b0","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/31814\/","title":{"rendered":"\u5982\u4f55\u663e\u793aWordPress\u67d0\u4e2a\u6587\u7ae0\u6240\u6709\u8bc4\u8bba\u8005\u540d\u79f0"},"content":{"rendered":"<p>\u4e0b\u9762\u7531\/&#8221; target=&#8221;_blank&#8221;&gt;<strong>wordpress<\/strong>\u6559\u7a0b\u680f\u76ee\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u663e\u793awordpress\u67d0\u4e2a\u6587\u7ae0\u6240\u6709\u8bc4\u8bba\u8005\u540d\u79f0\u7684\u529e\u6cd5\uff0c\u5e0c\u671b\u5bf9\u9700\u8981\u7684\u670b\u53cb\u6709\u6240\u5e2e\u52a9\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/020\/5faa3ab71c1f1297.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u663e\u793aWordPress\u67d0\u4e2a\u6587\u7ae0\u6240\u6709\u8bc4\u8bba\u8005\u540d\u79f0\u63d2\u56fe\" alt=\"\u5982\u4f55\u663e\u793aWordPress\u67d0\u4e2a\u6587\u7ae0\u6240\u6709\u8bc4\u8bba\u8005\u540d\u79f0\u63d2\u56fe\" \/><\/p>\n<p>\u5982\u679c\u60f3\u663e\u793a\u67d0\u7bc7\u6587\u7ae0\u6216\u5f53\u524d\u6587\u7ae0\u6240\u6709\u8bc4\u8bba\u8005\u540d\u79f0\u5217\u8868\uff0c\u53ef\u4ee5\u53c2\u8003\u4e00\u4e0b\u672c\u6587\u7684\u65b9\u6cd5\u3002<\/p>\n<p>\u4f7f\u7528\u573a\u666f\uff0c\u6bd4\u5982\u5728\u6587\u7ae0\u9002\u5f53\u4f4d\u7f6e\uff0c\u663e\u793a\u5f53\u524d\u5df2\u6709\uff1a\u53f2\u73cd\u9999\uff0c\u79e6\u5bff\u751f\uff0c\u7126\u539a\u6839\uff0c\u6731\u9038\u7fa4\uff0c\u590f\u5efa\u4ec1\u7b49\u53d1\u8868\u4e86\u70ed\u60c5\u626c\u6ea2\u7684\u8bc4\u8bba\uff0c\u518d\u52a0\u4e00\u4e2a\u951a\u70b9\u94fe\u63a5\uff0c\u5f15\u5bfc\u8bfb\u8005\u8df3\u8f6c\u5230\u8bc4\u8bba\u8868\u5355\uff0c\u4e5f\u53d1\u4e2a\u70ed\u60c5\u626c\u6ea2\u7684\u8bc4\u8bba\u3002<\/p>\n<p>\u5c06\u4ee3\u7801\u6dfb\u52a0\u5230\u5f53\u524d\u4e3b\u9898\u51fd\u6570\u6a21\u677ffunctions.php\u4e2d\uff1a<\/p>\n<pre>function&nbsp;get_comment_authors_list(&nbsp;$id&nbsp;=&nbsp;0,&nbsp;$sep&nbsp;=&nbsp;',&nbsp;'&nbsp;)&nbsp;{\n$post_id&nbsp;=&nbsp;$id&nbsp;?&nbsp;$id&nbsp;:&nbsp;get_the_ID();\nif&nbsp;(&nbsp;$post_id&nbsp;)&nbsp;{\n$comments&nbsp;=&nbsp;get_comments(&nbsp;array(\n'post_id'&nbsp;=&amp;gt;&nbsp;$post_id,\n'status'&nbsp;&nbsp;=&amp;gt;&nbsp;'approve',\n'type'&nbsp;&nbsp;&nbsp;&nbsp;=&amp;gt;&nbsp;'comment',\n)&nbsp;);\n&nbsp;\n$names&nbsp;=&nbsp;array();\nforeach&nbsp;(&nbsp;$comments&nbsp;as&nbsp;$comment&nbsp;)&nbsp;{\n$name&nbsp;=&nbsp;$comment-&amp;gt;comment_author;\nif&nbsp;(&nbsp;$comment-&amp;gt;user_id&nbsp;)&nbsp;{\n$user&nbsp;=&nbsp;get_userdata(&nbsp;$comment-&amp;gt;user_id&nbsp;);\n$name&nbsp;=&nbsp;$user&nbsp;?&nbsp;$user-&amp;gt;display_name&nbsp;:&nbsp;$name;\n}\n&nbsp;\n$arr&nbsp;=&nbsp;explode(&nbsp;'&nbsp;',&nbsp;trim(&nbsp;$name&nbsp;)&nbsp;);\nif&nbsp;(&nbsp;!&nbsp;empty(&nbsp;$arr[0]&nbsp;)&nbsp;&amp;amp;&amp;amp;&nbsp;!&nbsp;in_array(&nbsp;$arr[0],&nbsp;$names&nbsp;)&nbsp;)&nbsp;{\n$names[]&nbsp;=&nbsp;$arr[0];\n}\n}\nunset(&nbsp;$comments&nbsp;);\n&nbsp;\n$sep&nbsp;=&nbsp;$sep&nbsp;?&nbsp;$sep&nbsp;:&nbsp;',&nbsp;';\nreturn&nbsp;implode(&nbsp;$sep,&nbsp;$names&nbsp;);\n}\n}\n&nbsp;\n&nbsp;\nadd_shortcode(&nbsp;'comment_authors_list',&nbsp;'comment_authors_list_shortcode'&nbsp;);\n&nbsp;\nfunction&nbsp;comment_authors_list_shortcode(&nbsp;$atts&nbsp;=&nbsp;array()&nbsp;)&nbsp;{\n$atts&nbsp;=&nbsp;shortcode_atts(&nbsp;array(\n'post_id'&nbsp;&nbsp;=&amp;gt;&nbsp;0,\n'list_sep'&nbsp;=&amp;gt;&nbsp;'',\n),&nbsp;$atts&nbsp;);\n&nbsp;\nreturn&nbsp;get_comment_authors_list(&nbsp;$atts['post_id'],&nbsp;$atts['list_sep']&nbsp;);\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4f7f\u7528\u65b9\u6cd5\uff1a<\/p>\n<p>\u4e00\u3001\u8c03\u7528ID\u4e3a\uff1a123\u6587\u7ae0\u7684\u6240\u6709\u8bc4\u8bba\u8005\u540d\u79f0<\/p>\n<p>\u5728\u6a21\u677f\u4e2d\u4f7f\u7528\uff1a<\/p>\n<pre>&lt;?php  echo get_comment_authors_list(&#039;123&#039;); ?&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u6587\u7ae0\u6dfb\u52a0\u77ed\u4ee3\u7801\uff1a<\/p>\n<pre>[comment_authors_list&nbsp;post_id=\"123\"&nbsp;\/]<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4e8c\u3001\u8c03\u7528\u5f53\u524d\u6587\u7ae0\u6240\u6709\u8bc4\u8bba\u8005\u540d\u79f0\uff0c\u4e0e\u4e0a\u9762\u7c7b\u4f3c\u53ea\u662f\u53bb\u6389\u5176\u4e2d\u7684\u6587\u7ae0ID\uff0c\u9002\u5408\u653e\u5728\u6587\u7ae0\u6b63\u6587\u6a21\u677f\u4e2d\u3002<\/p>\n<p>\u5728\u6a21\u677f\u4e2d\u4f7f\u7528<\/p>\n<pre>&lt;?php  echo get_comment_authors_list(); ?&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u6587\u7ae0\u4e2d\u6dfb\u52a0\u77ed\u4ee3\u7801\uff1a<\/p>\n<pre>[comment_authors_list&nbsp;\/]<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u663e\u793aWordPress\u67d0\u4e2a\u6587\u7ae0\u6240\u6709\u8bc4\u8bba\u8005\u540d\u79f0\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e0b\u9762\u7531\/&#8221; target=&#8221;_blank&#8221;&gt;wordpress\u6559\u7a0b\u680f\u76ee\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u663e\u793awordpress\u67d0\u4e2a\u6587\u7ae0\u6240\u6709\u8bc4\u8bba\u8005\u540d\u79f0\u7684\u529e\u6cd5\uff0c\u5e0c\u671b\u5bf9\u9700\u8981\u7684\u670b\u53cb\u6709\u6240\u5e2e\u52a9\uff01 \u5982\u679c\u60f3\u663e\u793a\u67d0\u7bc7\u6587\u7ae0\u6216\u5f53\u524d\u6587\u7ae0\u6240\u6709\u8bc4\u8bba\u8005\u540d\u79f0\u5217\u8868\uff0c\u53ef\u4ee5\u53c2\u8003\u4e00\u4e0b\u672c\u6587\u7684\u65b9\u6cd5\u3002 \u4f7f\u7528\u573a\u666f\uff0c\u6bd4\u5982\u5728\u6587\u7ae0\u9002\u5f53\u4f4d\u7f6e\uff0c\u663e\u793a\u5f53\u524d\u5df2\u6709\uff1a\u53f2\u73cd\u9999\uff0c\u79e6\u5bff\u751f\uff0c\u7126\u539a\u6839\uff0c\u6731\u9038\u7fa4\uff0c\u590f\u5efa\u4ec1\u7b49\u53d1\u8868\u4e86\u70ed\u60c5\u626c\u6ea2\u7684\u8bc4\u8bba\uff0c\u518d\u52a0\u4e00\u4e2a\u951a\u70b9\u94fe\u63a5\uff0c\u5f15\u5bfc\u8bfb\u8005\u8df3\u8f6c\u5230\u8bc4\u8bba\u8868\u5355\uff0c\u4e5f\u53d1\u4e2a\u70ed\u60c5\u626c\u6ea2\u7684\u8bc4\u8bba\u3002 \u5c06\u4ee3\u7801\u6dfb\u52a0\u5230\u5f53\u524d\u4e3b\u9898\u51fd\u6570\u6a21\u677ffunctions.php\u4e2d\uff1a function&nbsp;get_comment_authors_list(&nbsp;$id&nbsp;=&nbsp;0,&nbsp;$sep&nbsp;=&nbsp;&#8216;,&nbsp;&#8216;&nbsp;)&nbsp;{ $post_id&nbsp;=&nbsp;$id&nbsp;?&nbsp;$id&nbsp;:&nbsp;get_the_ID(); if&nbsp;(&nbsp;$post_id&nbsp;)&nbsp;{ $comments&nbsp;=&nbsp;get_comments(&nbsp;array( &#8216;post_id&#8217;&nbsp;=&amp;gt;&nbsp;$post_id, &#8216;status&#8217;&nbsp;&nbsp;=&amp;gt;&nbsp;&#8216;approve&#8217;, &#8216;type&#8217;&nbsp;&nbsp;&nbsp;&nbsp;=&amp;gt;&nbsp;&#8216;comment&#8217;, )&nbsp;); &nbsp; $names&nbsp;=&nbsp;array(); foreach&nbsp;(&nbsp;$comments&nbsp;as&nbsp;$comment&nbsp;)&nbsp;{ $name&nbsp;=&nbsp;$comment-&amp;gt;comment_author; if&nbsp;(&nbsp;$comment-&amp;gt;user_id&nbsp;)&nbsp;{ $user&nbsp;=&nbsp;get_userdata(&nbsp;$comment-&amp;gt;user_id&nbsp;); $name&nbsp;=&nbsp;$user&nbsp;?&nbsp;$user-&amp;gt;display_name&nbsp;:&nbsp;$name; } &nbsp; $arr&nbsp;=&nbsp;explode(&nbsp;&#8216;&nbsp;&#8216;,&nbsp;trim(&nbsp;$name&nbsp;)&nbsp;); if&nbsp;(&nbsp;!&nbsp;empty(&nbsp;$arr[0]&nbsp;)&nbsp;&amp;amp;&amp;amp;&nbsp;!&nbsp;in_array(&nbsp;$arr[0],&nbsp;$names&nbsp;)&nbsp;)&nbsp;{ $names[]&nbsp;=&nbsp;$arr[0]; } } unset(&nbsp;$comments&nbsp;); &nbsp; $sep&nbsp;=&nbsp;$sep&nbsp;?&nbsp;$sep&nbsp;:&nbsp;&#8216;,&nbsp;&#8216;; return&nbsp;implode(&nbsp;$sep,&nbsp;$names&nbsp;); } } &nbsp; &nbsp; add_shortcode(&nbsp;&#8216;comment_authors_list&#8217;,&nbsp;&#8216;comment_authors_list_shortcode&#8217;&nbsp;); &nbsp; function&nbsp;comment_authors_list_shortcode(&nbsp;$atts&nbsp;=&nbsp;array()&nbsp;)&nbsp;{ $atts&nbsp;=&nbsp;shortcode_atts(&nbsp;array( &#8216;post_id&#8217;&nbsp;&nbsp;=&amp;gt;&nbsp;0, &#8216;list_sep&#8217;&nbsp;=&amp;gt;&nbsp;&#8221;, ),&nbsp;$atts&nbsp;); &nbsp; return&nbsp;get_comment_authors_list(&nbsp;$atts[&#8216;post_id&#8217;],&nbsp;$atts[&#8216;list_sep&#8217;]&nbsp;); } \u767b\u5f55\u540e\u590d\u5236 \u4f7f\u7528\u65b9\u6cd5\uff1a \u4e00\u3001\u8c03\u7528ID\u4e3a\uff1a123\u6587\u7ae0\u7684\u6240\u6709\u8bc4\u8bba\u8005\u540d\u79f0 \u5728\u6a21\u677f\u4e2d\u4f7f\u7528\uff1a &lt;?php echo get_comment_authors_list(&#039;123&#039;); ?&gt; \u767b\u5f55\u540e\u590d\u5236 \u5728\u6587\u7ae0\u6dfb\u52a0\u77ed\u4ee3\u7801\uff1a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-31814","post","type-post","status-publish","format-standard","hentry","category-cms"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/31814","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=31814"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/31814\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=31814"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=31814"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=31814"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}