Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.34 KB | None | 0 0
  1.           <div class="comments-central-section">
  2.           <h3>Recent Comments</h3>        
  3.           <ul>
  4.           <?php
  5.             // Recent comments
  6.             $max = 10; // item to get
  7.             global $wpdb;
  8.             $sql = "SELECT c.*, p.post_title FROM $wpdb->comments c INNER JOIN $wpdb->posts p ON (c.comment_post_id=p.ID) WHERE comment_approved = '1' AND comment_type not in ('trackback','pingback')";
  9.             $sql .= " ORDER BY comment_date DESC LIMIT $max";
  10.             $results = $wpdb->get_results($sql);
  11.            
  12.             $template = '<div class="who">%g <a href="%au">%an</a> on <a href="%pu#comment-%cid">%pt</a></div>';
  13.            
  14.             $echoed=0;
  15.             foreach ($results as $row) {
  16.               $tags = array('%ct','%cd','%g','%pt','%pu','%au','%an','%cid');
  17.               $replacements = array($row->comment_title,$row->comment_date,get_avatar($row->comment_author_email,'32'),$row->post_title,get_permalink($row->comment_post_ID),$row->comment_author_url,$row->comment_author,$row->comment_ID);
  18.               echo '<li>' . str_replace($tags,$replacements,$template) . '<div class="said">'. $row->comment_content . '</div></li>';
  19.               $echoed=1;
  20.             }
  21.             if ($echoed==0)
  22.                 echo '<li>None Found.</li>';        
  23.           ?>
  24.           </ul>
  25.           </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement