{"id":31,"date":"2005-03-14T20:59:26","date_gmt":"2005-03-15T00:59:26","guid":{"rendered":"http:\/\/hoogervorst.dyndns.org\/~arthur\/wordpress\/?p=31"},"modified":"2005-03-14T21:10:08","modified_gmt":"2005-03-15T01:10:08","slug":"get-the-comments","status":"publish","type":"post","link":"http:\/\/www.hoogervorst.ca\/arthur\/?p=31","title":{"rendered":"Get the comments"},"content":{"rendered":"<p><span class=\"dropcap\">O<\/span>K: the first WordPress hack, the last 7 comments on your blog (or whatever number you&#8217;d like). I like the way this is on Alan&#8217;s page where it&#8217;s called <a href=\"http:\/\/www.genx40.com\/\">&#8216;Active conversations&#8217;<\/a>. On Alan&#8217;s page the whole thread is lifted out (which is particularly neat too), in my case I only wanted to see the comments (and their permalinks).\n<\/p>\n<blockquote>\n<p>&lt;?php  if ( $comments = $wpdb->get_results(&#8220;SELECT comment_author, &#8221; .<br \/>\n         &#8220;comment_author_url, comment_ID, comment_post_ID &#8220;.<br \/>\n         &#8220;FROM $wpdb->comments WHERE comment_approved = &#8216;1&#8217; &#8221; .<br \/>\n         &#8220;ORDER BY comment_date_gmt DESC LIMIT 5&#8221;) ){<br \/>\n?><br \/>\n&lt;li><br \/>\n&lt;h2>&lt;?php _e(&#8216;Comments&#8217;); ?>&lt;\/h2><br \/>\n&lt;ul><br \/>\n&lt;?php  foreach ($comments as $comment) {<br \/>\n            echo &#8216;&lt;li>&#8217; .<br \/>\n              sprintf(&#8216;%s on %s&#8217;, $comment->comment_author,<br \/>\n              &#8216;&lt;a href=&#8221;&#8216;. get_permalink($comment->comment_post_ID) .<br \/>\n              &#8216;#comment-&#8216; . $comment->comment_ID . &#8216;&#8221;>&#8217; .<br \/>\n              get_the_title($comment->comment_post_ID) . &#8216;&lt;\/a>&#8217;);<br \/>\n            echo &#8216;&lt;\/li>&#8217;;     }<br \/>\n}<br \/>\n?><\/p>\n<p>&lt;\/ul>&lt;\/li><\/p>\n<\/blockquote>\n<p>Paste the code in your theme&#8217;s sidebar.php file (somewhere between line 44 and line 50).\n<\/p>\n<p>Some observations: First of all, I like to see a date. Maybe I should group the data first and then print (echo)  it off.  Secondly, look at the get_the_title! It gets an ID as a parameter which means that there&#8217;s going to be another query fired off on the server. Not really efficient (note, this code you can also find [minus the small change] in your WordPress dashboard) . Tell the boys that. <\/p>\n<p>More after.\n<\/p>\n<p><small>ed: I went through great lengths getting the code to show up nice. Watch out for extra spaces when you copy the snippet. Also, if you have a spare *nux computer to play with, I highly recommend you to test it on that machine first.<\/small><\/p>\n","protected":false},"excerpt":{"rendered":"<p>OK: the first WordPress hack, the last 7 comments on your blog (or whatever number you&#8217;d like). I like the way this is on Alan&#8217;s page where it&#8217;s called &#8216;Active conversations&#8217;. On Alan&#8217;s page the whole thread is lifted out &hellip; <a href=\"http:\/\/www.hoogervorst.ca\/arthur\/?p=31\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[2,16],"tags":[],"_links":{"self":[{"href":"http:\/\/www.hoogervorst.ca\/arthur\/index.php?rest_route=\/wp\/v2\/posts\/31"}],"collection":[{"href":"http:\/\/www.hoogervorst.ca\/arthur\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.hoogervorst.ca\/arthur\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.hoogervorst.ca\/arthur\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.hoogervorst.ca\/arthur\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=31"}],"version-history":[{"count":0,"href":"http:\/\/www.hoogervorst.ca\/arthur\/index.php?rest_route=\/wp\/v2\/posts\/31\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.hoogervorst.ca\/arthur\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=31"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.hoogervorst.ca\/arthur\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=31"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.hoogervorst.ca\/arthur\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=31"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}