Advertisement
Guest User

Widget

a guest
Dec 15th, 2012
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.41 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->$id_or_email , 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 ); ?> minutes ago</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. <?php
  81. wp_reset_postdata();
  82. wp_reset_query();
  83. ?>
  84. <?php global $wpdb;//".$wpdb->prefix."
  85. $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;
  86. $query_posts = $wpdb->get_results($query,OBJECT);
  87. ?>
  88. <?php if($query_posts){ ?>
  89. <div id="popular_posts">
  90. <ul class="recent_posts small_plus">
  91. <!-- Post Entry -->
  92. <?php
  93. foreach($query_posts as $post)
  94. {
  95. $post_new = get_post($post->post_id_com);
  96. ?>
  97. <li>
  98. <div class="post_thumb">
  99. <a href="<?php echo $post_new->guid; ?>" >
  100. <?php echo get_the_post_thumbnail($post->post_id_com, 'image-10') ?>
  101. </a>
  102. </div>
  103. <div class="post_info">
  104. <a href="<?php echo $post_new->guid; ?>" class="title">
  105. <?php echo $post_new->post_title ?>
  106. </a>
  107. <div class="author_date">
  108. By <a href="<?php echo get_the_author_meta( 'user_url', $post_new->post_author); ?>">
  109. <?php echo get_the_author_meta( 'user_nicename', $post_new->post_author); ?>
  110. </a> at <a href="#"><?php echo $post_new->post_date ?></a>
  111. </div>
  112. </div>
  113. <div class="clear"></div>
  114. </li>
  115. <?php
  116. }
  117. wp_reset_postdata();
  118. wp_reset_query();
  119. ?>
  120. <!-- End of: Post Entry -->
  121. </ul>
  122. </div>
  123. <?php } ?>
  124. </div>
  125. <?php
  126. echo $after_widget;
  127. }
  128. /**
  129. * Deals with the settings when they are saved by the admin. Here is
  130. * where any validation should be dealt with.
  131. **/
  132. function update( $new_instance, $old_instance ) {
  133. $instance = array();
  134. $instance['comment'] = strip_tags( $new_instance['comment'] );
  135. $instance['posts'] = strip_tags( $new_instance['posts'] );
  136. $instance['comment_size'] = strip_tags( $new_instance['comment_size'] );
  137. $instance['posts_size'] = strip_tags( $new_instance['posts_size'] );
  138. return $instance;
  139. }
  140. /**
  141. * Displays the form for this widget on the Widgets page of the WP Admin area.
  142. **/
  143. function form( $instance ) {
  144.  
  145. $comment = $instance[ 'comment' ];
  146. $posts = $instance[ 'posts' ];
  147. $comment_size = $instance[ 'comment_size' ];
  148. $posts_size = $instance[ 'posts_size' ];
  149. ?>
  150. <p>
  151. <label for="<?php echo $this->get_field_id( 'comment' ); ?>"><?php _e( 'Comment Title:' , 'tauno'); ?></label>
  152. <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 ); ?>" />
  153. </p>
  154. <p>
  155. <label for="<?php echo $this->get_field_id( 'comment_size' ); ?>"><?php _e( 'Items Show :' , 'tauno'); ?></label>
  156. <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 ); ?>" />
  157. </p>
  158. <p>
  159. <label for="<?php echo $this->get_field_id( 'posts' ); ?>"><?php _e( 'Post Title:' , 'tauno'); ?></label>
  160. <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 ); ?>" />
  161. </p>
  162. <p>
  163. <label for="<?php echo $this->get_field_id( 'posts_size' ); ?>"><?php _e( 'Items Show :', 'tauno' ); ?></label>
  164. <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 ); ?>" />
  165. </p>
  166. <?php
  167. }
  168. }
  169. function myplugin_register_widgets_ppcm() {
  170. register_widget( 'Popular_Comments' );
  171. }
  172. add_action( 'widgets_init', 'myplugin_register_widgets_ppcm' );
  173. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement