Advertisement
Guest User

Widget

a guest
Jan 30th, 2013
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.36 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Makes a custom Widget for displaying Aside, Link, Status, and Quote Posts available with Twenty Eleven
  4.  *
  5.  *
  6.  * @package WordPress
  7.  * @subpackage Tauno
  8.  * @since Tauno 1.0
  9.  */
  10. class Popular_Comments extends WP_Widget {
  11.     /**
  12.      * Constructor
  13.      *
  14.      * @return void
  15.      **/
  16.     function Popular_Comments() {
  17.         $widget_ops = array( 'classname' => 'tabs', 'description' => __( 'Show popular Posts and recent Comments', 'tauno' ) );
  18.         $this->WP_Widget( 'tabs_populra_comments', __( 'Show Posts and Comments', 'tauno' ), $widget_ops );
  19.         $this->alt_option_name = 'tabs_populra_comments';
  20.     }
  21.     /**
  22.      * Outputs the HTML for this widget.
  23.      *
  24.      * @param array An array of standard parameters for widgets in this theme
  25.      * @param array An array of settings for this widget instance
  26.      * @return void Echoes it's output
  27.      **/
  28.     function widget( $args, $instance ) {
  29.         extract( $args );
  30.         $title = apply_filters( 'widget_title', $instance['title'] );
  31.        
  32.         echo $before_widget;
  33.         if ( ! empty( $title ) )
  34.             //echo $before_title . $title . $after_title;
  35.        
  36.         $comment_title = $instance['comment'];
  37.         $post_title  = $instance['posts'];
  38.         $comment_size = $instance['comment_size'];
  39.         $post_size = $instance['posts_size'];
  40.        
  41.         ?>
  42.         <div class="tabs_titles">
  43.             <a href="#recent_comments" class="active"><?php echo $instance['comment'];?></a>
  44.             <a href="#popular_posts"><?php echo $instance['posts'];?></a>
  45.         </div>
  46.        
  47.         <div class="clear"></div>
  48.        
  49.         <div class="tab_content">
  50.             <!-- Recent Comments Tab -->
  51.             <?php $defaults = array(                       
  52.                     'number' => $comment_size ,                    
  53.                     'status' => 'approve'                      
  54.                     ); ?>
  55.                    
  56.             <?php $comments = get_comments( $defaults ); ?>
  57.             <?php if($comments) { ?>       
  58.             <div id="recent_comments">
  59.                 <ul class="recent_comments">
  60.                     <?php foreach($comments as $comment) : ?>
  61.                     <li>
  62.                         <div class="author_thumb">
  63.                             <?php echo get_avatar( $comment, 54 ); ?>
  64.                         </div>                        
  65.                        
  66.                         <div class="author_info">                        
  67.                             <a href="<?php echo($comment->comment_author_url); ?>" class="author_name"><?php echo($comment->comment_author); ?></a>                             <span class="timespan"><?php echo($comment->comment_date ); ?></span>                        
  68.                             <p>
  69.                                <?php echo($comment->comment_content); ?>
  70.                             </p>
  71.                         </div>                        
  72.                        
  73.                         <div class="clear"></div>                      
  74.                     </li>              
  75.                     <?php endforeach;?>
  76.                 </ul>
  77.             </div>
  78.             <!-- End of: Recent Comments Tab -->
  79.             <?php
  80.             wp_reset_postdata();
  81.             wp_reset_query();
  82.             ?>
  83.             <?php global $wpdb;//".$wpdb->prefix."
  84.             $query = "SELECT wpp.post_title, wpp.ID as post_id_com , count(comment_ID) com_id, comment_post_ID, user_id FROM ".$wpdb->prefix."comments wc inner join ".$wpdb->prefix."posts wpp where post_type='post' && wc.comment_post_id = wpp.ID group by comment_post_ID order by com_id desc limit ".$post_size;        
  85.             $query_posts = $wpdb->get_results($query,OBJECT);  
  86.             ?>
  87.             <?php if($query_posts){ ?>
  88.             <div id="popular_posts">
  89.                 <ul class="recent_posts small_plus">
  90.                     <!-- Post Entry -->
  91.                     <?php                  
  92.                     foreach($query_posts as $post)
  93.                     {
  94.                         $post_new = get_post($post->post_id_com);
  95.                         ?>
  96.                         <li>
  97.                             <div class="post_thumb">
  98.                                 <a href="<?php echo $post_new->guid; ?>" >
  99.                                     <?php echo get_the_post_thumbnail($post->post_id_com, 'image-10') ?>
  100.                                 </a>
  101.                             </div>
  102.                             <div class="post_info">
  103.                                 <a href="<?php echo $post_new->guid; ?>" class="title">
  104.                                     <?php echo $post_new->post_title ?>
  105.                                 </a>
  106.                                 <div class="author_date">
  107.                                 Por <a href="<?php echo get_the_author_meta( 'user_url', $post_new->post_author); ?>">
  108.                                 <?php echo get_the_author_meta( 'user_nicename', $post_new->post_author); ?>
  109.                                 </a> em <a href="#"><?php echo $post_new->post_date  ?></a>
  110.                                 </div>
  111.                             </div>
  112.                             <div class="clear"></div>
  113.                         </li>                      
  114.                     <?php
  115.                     }
  116.                     wp_reset_postdata();
  117.                     wp_reset_query();
  118.                     ?>                
  119.                     <!-- End of: Post Entry -->
  120.                 </ul>
  121.             </div>
  122.             <?php } ?>
  123.         </div>        
  124.         <?php
  125.         echo $after_widget;
  126.     }
  127.     /**
  128.      * Deals with the settings when they are saved by the admin. Here is
  129.      * where any validation should be dealt with.
  130.      **/
  131.     function update( $new_instance, $old_instance ) {      
  132.         $instance = array();
  133.         $instance['comment'] = strip_tags( $new_instance['comment'] );
  134.         $instance['posts'] = strip_tags( $new_instance['posts'] );
  135.         $instance['comment_size'] = strip_tags( $new_instance['comment_size'] );
  136.         $instance['posts_size'] = strip_tags( $new_instance['posts_size'] );
  137.         return $instance;
  138.     }
  139.     /**
  140.      * Displays the form for this widget on the Widgets page of the WP Admin area.
  141.      **/
  142.     function form( $instance ) {
  143.    
  144.         $comment =  $instance[ 'comment' ];
  145.         $posts =  $instance[ 'posts' ];
  146.         $comment_size =  $instance[ 'comment_size' ];
  147.         $posts_size =  $instance[ 'posts_size' ];
  148.         ?>
  149.         <p>
  150.         <label for="<?php echo $this->get_field_id( 'comment' ); ?>"><?php _e( 'Comment Title:' , 'tauno'); ?></label>
  151.         <input class="widefat" id="<?php echo $this->get_field_id( 'comment' ); ?>" name="<?php echo $this->get_field_name( 'comment' ); ?>" type="text" value="<?php echo esc_attr( $comment ); ?>" />
  152.         </p>
  153.         <p>
  154.         <label for="<?php echo $this->get_field_id( 'comment_size' ); ?>"><?php _e( 'Items Show :' , 'tauno'); ?></label>
  155.         <input class="widefat" id="<?php echo $this->get_field_id( 'comment_size' ); ?>" name="<?php echo $this->get_field_name( 'comment_size' ); ?>" type="text" value="<?php echo esc_attr( $comment_size ); ?>" />
  156.         </p>
  157.         <p>
  158.         <label for="<?php echo $this->get_field_id( 'posts' ); ?>"><?php _e( 'Post Title:' , 'tauno'); ?></label>
  159.         <input class="widefat" id="<?php echo $this->get_field_id( 'posts' ); ?>" name="<?php echo $this->get_field_name( 'posts' ); ?>" type="text" value="<?php echo esc_attr( $posts ); ?>" />
  160.         </p>
  161.         <p>
  162.         <label for="<?php echo $this->get_field_id( 'posts_size' ); ?>"><?php _e( 'Items Show :', 'tauno' ); ?></label>
  163.         <input class="widefat" id="<?php echo $this->get_field_id( 'posts_size' ); ?>" name="<?php echo $this->get_field_name( 'posts_size' ); ?>" type="text" value="<?php echo esc_attr( $posts_size ); ?>" />
  164.         </p>
  165.         <?php
  166.     }
  167. }
  168. function myplugin_register_widgets_ppcm() {
  169.     register_widget( 'Popular_Comments' );
  170. }
  171. add_action( 'widgets_init', 'myplugin_register_widgets_ppcm' );
  172. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement