__( 'Just a simple widget that displays recent comments.', 'vh' ), ) ); } // Creating widget front-end // This is where the action happens public function widget( $args, $instance ) { global $post, $wpdb, $wp_query; $maintitle = $instance['maintitle']; $limit = $instance['limit']; $thePostID = $wp_query->post->ID; // before and after widget arguments are defined by themes echo $args['before_widget']; if ( !empty($maintitle) ) { echo '
'; echo '

' . $maintitle . '

'; echo '
'; } if ( empty($limit) ) { $limit = 5; } $querystr = "SELECT comment_author, comment_author_email, comment_content, comment_post_ID FROM " . $wpdb->prefix . "comments ORDER BY comment_date DESC LIMIT ".$limit; $queryresults = $wpdb->get_results($querystr); if ( !empty($queryresults) ) { echo "
"; foreach ($queryresults as $value) { echo "
"; echo "
"; echo '' . get_avatar($value->comment_author_email, 22) . ''; echo '' . $value->comment_author . ':'; echo "
"; echo "
"; echo ''; if ( strlen($value->comment_content) > 50 ) { $comment_content = substr($value->comment_content, 0, 50) . '..'; } else { $comment_content = $value->comment_content; } echo wp_kses( $comment_content, array( 'a' => array( 'href' => array(), 'class' => array() ) ) ); echo ''; echo "
"; echo "
"; echo '' . get_the_title( $value->comment_post_ID ) . ''; echo "
"; echo "
"; } echo "
"; } else { echo "
"; _e('There hasn\'t been any activity in this listing.', 'vh'); echo "
"; } echo $args['after_widget']; } // Widget Backend public function form( $instance ) { if ( isset( $instance[ 'maintitle' ] ) ) { $maintitle = $instance[ 'maintitle' ]; } else { $maintitle = ''; } if ( isset( $instance[ 'limit' ] ) ) { $limit = $instance[ 'limit' ]; } else { $limit = ''; } // Widget admin form ?>