dajare

Recent comments code

Jan 2nd, 2011
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.51 KB | None | 0 0
  1. <?php
  2.  // RETRIEVES n RECENT COMMENTS FOR FRONTEND DISPLAY IN WOLF CMS
  3. global $__CMS_CONN__;
  4. $sql = "SELECT COUNT(*) FROM ".TABLE_PREFIX."comment WHERE is_approved = 1";
  5. $stmt = $__CMS_CONN__->query($sql);
  6. $comments_count = $stmt->fetchColumn();
  7. $stmt->closeCursor();
  8.  
  9. $limit = 3; // SET NUMBER OF COMMENTS TO RETRIEVE
  10.  
  11. $totalrecords = $comments_count;
  12. $sql = "SELECT comment.is_approved, comment.id, comment.page_id, comment.author_name, comment.author_link, comment.body, comment.created_on, page.title, page.id FROM " .
  13.     TABLE_PREFIX . "comment AS comment, " . TABLE_PREFIX .
  14.     "page AS page WHERE comment.is_approved = 1 AND comment.page_id = page.id ORDER BY comment.id DESC LIMIT " . $limit;
  15.  
  16. $stmt = $__CMS_CONN__->prepare($sql);
  17. $stmt->execute();
  18. ?>
  19.  
  20. <ul id="recent-comments">
  21.     <?php while ($comment = $stmt->fetchObject()): ?>
  22.     <li>
  23.           <strong><?php if ($comment->author_link != '') {
  24.             echo '<a href="'.$comment->author_link.'" title="'.$comment->author_name.'">'.$comment->author_name.'</a>';
  25.         }  else { echo $comment->author_name; } ?></strong>
  26.  <?php echo __('on'); ?> <strong><?php echo Page::linkById(intval($comment->id)); // $comment->id; ?></strong>
  27.           <span class="comment-date">
  28.               (<?php echo date('D, j M Y', strtotime($comment->created_on)); ?>)
  29.           </span>
  30. <?php /* remove PHP comments (and line-after-next) to include comment text: ?>
  31.           <p><?php echo $comment->body; ?></p>
  32. <?php */ ?>
  33.       </li>
  34. <?php endwhile; ?>
  35. </ul>
Add Comment
Please, Sign In to add comment