Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Makes a custom Widget for displaying Aside, Link, Status, and Quote Posts available with Twenty Eleven
- *
- *
- * @package WordPress
- * @subpackage Tauno
- * @since Tauno 1.0
- */
- class Popular_Comments extends WP_Widget {
- /**
- * Constructor
- *
- * @return void
- **/
- function Popular_Comments() {
- $widget_ops = array( 'classname' => 'tabs', 'description' => __( 'Show popular Posts and recent Comments', 'tauno' ) );
- $this->WP_Widget( 'tabs_populra_comments', __( 'Show Posts and Comments', 'tauno' ), $widget_ops );
- $this->alt_option_name = 'tabs_populra_comments';
- }
- /**
- * Outputs the HTML for this widget.
- *
- * @param array An array of standard parameters for widgets in this theme
- * @param array An array of settings for this widget instance
- * @return void Echoes it's output
- **/
- function widget( $args, $instance ) {
- extract( $args );
- $title = apply_filters( 'widget_title', $instance['title'] );
- echo $before_widget;
- if ( ! empty( $title ) )
- //echo $before_title . $title . $after_title;
- $comment_title = $instance['comment'];
- $post_title = $instance['posts'];
- $comment_size = $instance['comment_size'];
- $post_size = $instance['posts_size'];
- ?>
- <div class="tabs_titles">
- <a href="#recent_comments" class="active"><?php echo $instance['comment'];?></a>
- <a href="#popular_posts"><?php echo $instance['posts'];?></a>
- </div>
- <div class="clear"></div>
- <div class="tab_content">
- <!-- Recent Comments Tab -->
- <?php $defaults = array(
- 'number' => $comment_size ,
- 'status' => 'approve'
- ); ?>
- <?php $comments = get_comments( $defaults ); ?>
- <?php if($comments) { ?>
- <div id="recent_comments">
- <ul class="recent_comments">
- <?php foreach($comments as $comment) : ?>
- <li>
- <div class="author_thumb">
- <?php echo get_avatar( $comment->$id_or_email , 54); ?>
- </div>
- <div class="author_info">
- <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>
- <p>
- <?php echo($comment->comment_content); ?>
- </p>
- </div>
- <div class="clear"></div>
- </li>
- <?php endforeach;?>
- </ul>
- </div>
- <!-- End of: Recent Comments Tab -->
- <?php } ?>
- <?php
- wp_reset_postdata();
- wp_reset_query();
- ?>
- <?php global $wpdb;//".$wpdb->prefix."
- $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;
- $query_posts = $wpdb->get_results($query,OBJECT);
- ?>
- <?php if($query_posts){ ?>
- <div id="popular_posts">
- <ul class="recent_posts small_plus">
- <!-- Post Entry -->
- <?php
- foreach($query_posts as $post)
- {
- $post_new = get_post($post->post_id_com);
- ?>
- <li>
- <div class="post_thumb">
- <a href="<?php echo $post_new->guid; ?>" >
- <?php echo get_the_post_thumbnail($post->post_id_com, 'image-10') ?>
- </a>
- </div>
- <div class="post_info">
- <a href="<?php echo $post_new->guid; ?>" class="title">
- <?php echo $post_new->post_title ?>
- </a>
- <div class="author_date">
- By <a href="<?php echo get_the_author_meta( 'user_url', $post_new->post_author); ?>">
- <?php echo get_the_author_meta( 'user_nicename', $post_new->post_author); ?>
- </a> at <a href="#"><?php echo $post_new->post_date ?></a>
- </div>
- </div>
- <div class="clear"></div>
- </li>
- <?php
- }
- wp_reset_postdata();
- wp_reset_query();
- ?>
- <!-- End of: Post Entry -->
- </ul>
- </div>
- <?php } ?>
- </div>
- <?php
- echo $after_widget;
- }
- /**
- * Deals with the settings when they are saved by the admin. Here is
- * where any validation should be dealt with.
- **/
- function update( $new_instance, $old_instance ) {
- $instance = array();
- $instance['comment'] = strip_tags( $new_instance['comment'] );
- $instance['posts'] = strip_tags( $new_instance['posts'] );
- $instance['comment_size'] = strip_tags( $new_instance['comment_size'] );
- $instance['posts_size'] = strip_tags( $new_instance['posts_size'] );
- return $instance;
- }
- /**
- * Displays the form for this widget on the Widgets page of the WP Admin area.
- **/
- function form( $instance ) {
- $comment = $instance[ 'comment' ];
- $posts = $instance[ 'posts' ];
- $comment_size = $instance[ 'comment_size' ];
- $posts_size = $instance[ 'posts_size' ];
- ?>
- <p>
- <label for="<?php echo $this->get_field_id( 'comment' ); ?>"><?php _e( 'Comment Title:' , 'tauno'); ?></label>
- <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 ); ?>" />
- </p>
- <p>
- <label for="<?php echo $this->get_field_id( 'comment_size' ); ?>"><?php _e( 'Items Show :' , 'tauno'); ?></label>
- <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 ); ?>" />
- </p>
- <p>
- <label for="<?php echo $this->get_field_id( 'posts' ); ?>"><?php _e( 'Post Title:' , 'tauno'); ?></label>
- <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 ); ?>" />
- </p>
- <p>
- <label for="<?php echo $this->get_field_id( 'posts_size' ); ?>"><?php _e( 'Items Show :', 'tauno' ); ?></label>
- <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 ); ?>" />
- </p>
- <?php
- }
- }
- function myplugin_register_widgets_ppcm() {
- register_widget( 'Popular_Comments' );
- }
- add_action( 'widgets_init', 'myplugin_register_widgets_ppcm' );
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement