Want more features on Pastebin? Sign Up, it's FREE!
Guest

WordPress Comments Central Page Template

By: a guest on Feb 24th, 2010  |  syntax: PHP  |  size: 6.98 KB  |  views: 959  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. /**
  3.  * Template Name: Comments Central Page
  4.  *
  5.  *
  6.  */
  7. ?>
  8. <?php get_header(); ?>
  9.         <div id="container">
  10.        
  11.     <div id="content">
  12.    
  13.     <?php if (have_posts()) : ?>
  14.     <?php while (have_posts()) : the_post(); ?>    
  15.       <div id="comments-central" class="post clearfloat">
  16.         <h2 class="title"><?php the_title(); ?></h2>
  17.  
  18.           <!-- enough fluff, let's read! -->
  19.           <div class="read page-content">
  20.             <?php the_content('Read the rest of this entry &raquo;'); ?>
  21.  
  22.           <?php global $user_ID;
  23.             if( $user_ID ) :
  24.               if( current_user_can('level_10') ) : ?>
  25.      
  26.           <?php
  27.             $num_comm = wp_count_comments();
  28.           ?>
  29.           <div id="comments-central-admin">
  30.             <span>Total Comments: <a href="<?php bloginfo('wpurl'); ?>/wp-admin/edit-comments.php?"><? echo $num_comm->total_comments; ?></a></span>
  31.             <span>Approved: <a href="<?php bloginfo('wpurl'); ?>/wp-admin/edit-comments.php?comment_status=approved"><? echo $num_comm->approved; ?></a></span>
  32.             <span>Moderated: <a href="<?php bloginfo('wpurl'); ?>/wp-admin/edit-comments.php?comment_status=moderated"><? echo $num_comm->moderated; ?></a></span>
  33.             <span>Spam: <a href="<?php bloginfo('wpurl'); ?>/wp-admin/edit-comments.php?comment_status=spam"><? echo $num_comm->spam; ?> </a></span>
  34.           </div>
  35.  
  36.           <?php
  37.               endif;
  38.             endif; ?>        
  39.  
  40.           <?php
  41.             if(function_exists('activitysparks')) {
  42.           ?><h3>Comments Activity in the last 2 years</h3>
  43.           <?php
  44.             activitysparks(array('dataset'=>'legend','height_px'=>100,'width_px'=>500,'period'=>30, 'ticks'=>24));     
  45.             } ?>  
  46.                
  47.           <div class="comments-central-section">
  48.           <h3>Recent Comments</h3>        
  49.           <ul>
  50.           <?php
  51.             // Recent comments
  52.             $max = 10; // item to get
  53.             global $wpdb;
  54.             $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')";
  55.             $sql .= " ORDER BY comment_date DESC LIMIT $max";
  56.             $results = $wpdb->get_results($sql);
  57.            
  58.             $template = '<div class="who">%g <a href="%au">%an</a> on <a href="%pu#comment-%cid">%pt</a></div>';
  59.            
  60.             $echoed=0;
  61.             foreach ($results as $row) {
  62.               $tags = array('%ct','%cd','%g','%pt','%pu','%au','%an','%cid');
  63.               $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);
  64.               echo '<li>' . str_replace($tags,$replacements,$template) . '<div class="said">'. $row->comment_content . '</div></li>';
  65.               $echoed=1;
  66.             }
  67.             if ($echoed==0)
  68.                 echo '<li>None Found.</li>';        
  69.           ?>
  70.           </ul>
  71.           </div>
  72.           <div class="comments-central-section">
  73.           <h3>Recent Trackback / Pingback</h3>
  74.           <ul>
  75.           <?php
  76.             // Recent trackback / pingback
  77.             global $wpdb;
  78.             $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 in ('trackback','pingback')";
  79.             $sql .= " ORDER BY comment_date DESC LIMIT $max";
  80.             $results = $wpdb->get_results($sql);
  81.            
  82.             $template = '<a href="%au">%an</a> on <a href="%pu">%pt</a>';
  83.            
  84.             $echoed=0;
  85.             foreach ($results as $row) {
  86.               $tags = array('%ct','%cd','%g','%pt','%pu','%au','%an','%cid');
  87.               $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);
  88.               echo '<li>' . str_replace($tags,$replacements,$template) . '</li>';
  89.               $echoed=1;
  90.             }
  91.             if ($echoed==0)
  92.                 echo '<li>None Found.</li>';        
  93.           ?>
  94.           </ul>
  95.           </div>
  96.           <div class="comments-central-section">        
  97.           <h3>Most Active Discussions</h3>
  98.           <ul>
  99.           <?php
  100.             // Most active discussion
  101.             global $wpdb;
  102.             $sql = "SELECT p.*, c.comment_count FROM $wpdb->posts p INNER JOIN (SELECT comment_post_id, count(comment_ID) as comment_count from $wpdb->comments WHERE comment_approved='1'";
  103.             $sql .= " GROUP BY comment_post_id) c ON (c.comment_post_id=p.ID) ORDER BY c.comment_count DESC LIMIT $max";
  104.             $results = $wpdb->get_results($sql);
  105.            
  106.             $template = '<a href="%pu">%pt</a> (%c comments)';
  107.            
  108.             $echoed=0;
  109.             foreach ($results as $row) {
  110.                 $tags = array('%pd','%pt','%pu','%c');
  111.                 $replacements = array($row->post_date,$row->post_title,get_permalink($row->ID),$row->comment_count);
  112.                 echo '<li>' . str_replace($tags,$replacements,$template) . '</li>';
  113.                 $echoed=1;
  114.             }
  115.             if ($echoed==0)
  116.                 echo '<li>None Found.</li>';        
  117.           ?>
  118.           </ul>
  119.           </div>
  120.           <div class="comments-central-section">
  121.           <h3>Most Active Commenter</h3>
  122.           <ul>
  123.           <?php
  124.             // Most active commenter
  125.             global $wpdb;
  126.             $sql = "SELECT comment_author, comment_author_url, comment_author_email, count(comment_ID) as comment_count FROM $wpdb->comments WHERE comment_approved = '1' AND comment_type not in ('trackback','pingback')";
  127.             $sql .= " GROUP BY comment_author, comment_author_url, comment_author_email ORDER BY comment_count DESC LIMIT $max";
  128.             $results = $wpdb->get_results($sql);
  129.            
  130.             $template = '<div class="who"<a href="%au">%g %an</a> (%c comments)</div>';
  131.            
  132.             $echoed=0;
  133.             foreach ($results as $row) {
  134.                 $tags = array('%g','%au','%an','%c');
  135.                 $replacements = array(get_avatar($row->comment_author_email,'32'),$row->comment_author_url,$row->comment_author,$row->comment_count);
  136.                 echo '<li>' . str_replace($tags,$replacements,$template) . '</li>';
  137.                 $echoed=1;
  138.             }
  139.             if ($echoed==0)
  140.                 echo '<li>None Found.</li>';        
  141.           ?>
  142.           </ul>
  143.           </div>
  144.         </div>
  145.       </div> <!-- .post -->
  146.  
  147.                 <?php endwhile; ?>
  148.    
  149.     <?php else : ?>
  150.  
  151.       <h2 class="center">Not Found</h2>
  152.       <p class="center">Sorry, but you are looking for something that isn't here.</p>
  153.  
  154.     <?php endif; ?>
  155.     </div> <!-- #content -->
  156.  
  157. <?php get_sidebar(); ?>
  158. <?php get_footer(); ?>
clone this paste RAW Paste Data