__( 'Widget to show Recent Post, Recent Comment, Popular Post and Archive in nice tabing.', 'aspearl_rrpa' ), ) ); } /* * Creating widget front-end. This is where the action happens * * @params Array $args * @params Object $instance */ public function widget( $args, $instance ) { $title = apply_filters( 'widget_title', $instance['title'] ); // before and after widget arguments are defined by themes echo $args['before_widget']; if ( ! empty( $title ) ) echo $args['before_title'] . $title . $args['after_title']; // This is where you run the code and display the output $instance['no_of_records'] = ( ! empty( $instance[ 'no_of_records']) && (int)$instance[ 'no_of_records'] > 0) ? $instance[ 'no_of_records'] : 10; $instance['show_recent'] = ( ! empty( $instance['show_recent'] ) ) ? strip_tags( $instance['show_recent'] ) : 'yes'; $instance['show_popuplar'] = ( ! empty( $instance['show_popuplar'] ) ) ? strip_tags( $instance['show_popuplar'] ) : 'yes'; $instance['show_comment'] = ( ! empty( $instance['show_comment'] ) ) ? strip_tags( $instance['show_comment'] ) : 'yes'; $instance['show_archive'] = ( ! empty( $instance['show_archive'] ) ) ? strip_tags( $instance['show_archive'] ) : 'yes'; showWidgetHtml($instance); echo $args['after_widget']; } /* Widget Backend Configuration */ public function form( $instance ) { if ( isset( $instance[ 'title' ] ) ) { $title = $instance[ 'title' ]; } else { $title = __( '', 'wpb_widget_domain' ); } $noOfRecords = ( ! empty( $instance['no_of_records'] ) ) ? strip_tags( $instance['no_of_records'] ) : ''; $showRecent = ( ! empty( $instance['show_recent'] ) ) ? strip_tags( $instance['show_recent'] ) : 'yes'; $showPopuplar = ( ! empty( $instance['show_popuplar'] ) ) ? strip_tags( $instance['show_popuplar'] ) : 'yes'; $showComment = ( ! empty( $instance['show_comment'] ) ) ? strip_tags( $instance['show_comment'] ) : 'yes'; $showArchive = ( ! empty( $instance['show_archive'] ) ) ? strip_tags( $instance['show_archive'] ) : 'yes'; // Widget admin form ?>
/>
/>
/>
/>
'Show Recent', 'loop'=>true, 'data'=>$recent, 'no_msg'=>'No Recent Post Found.'); } if($instance['show_popuplar']=='yes') { $popular = getPopuplarPost($instance); $tabList['popular'] = array('label'=>'Show Popuplar', 'loop'=>true, 'data'=>$popular, 'no_msg'=>'No Popuplar Post Found.'); } if($instance['show_comment']=='yes') { $comment = getPostCommets($instance); $tabList['comment'] = array('label'=>'Show Comment', 'loop'=>true, 'data'=>$comment, 'no_msg'=>'No Comments Found.'); } if($instance['show_archive']=='yes') { $archive = getArchivePost($instance); $tabList['archive'] = array('label'=>'Show Archive', 'loop'=>false, 'data'=>$archive, 'no_msg'=>'No Archived Post Found.'); } include_once dirname(__FILE__).'/aspearl-rrpa-view.php'; } function getRecentPost($instance){ $noOfRecords = $instance[ 'no_of_records' ]; $args = array( 'numberposts' =>$noOfRecords, 'offset' => 0, 'category' => 0, 'orderby' => 'post_date', 'order' => 'DESC', 'post_type' => 'post', 'post_status' => 'publish', 'suppress_filters' => true ); return $recentPosts = wp_get_recent_posts( $args, OBJECT ); } function getPopuplarPost($instance){ $noOfRecords = $instance[ 'no_of_records' ]; $args = array( 'numberposts' => $noOfRecords, 'offset' => 0, 'category' => 0, 'orderby' => 'comment_count', 'order' => 'DESC', //'include' => , // 'exclude' => , //'meta_key' => , //'meta_value' =>, 'post_type' => 'post', 'post_status' => 'publish', 'suppress_filters' => true ); return $recentPosts = get_posts( $args, OBJECT ); } function getPostCommets($instance){ $noOfRecords = $instance[ 'no_of_records' ]; $defaults = array( 'include_unapproved' => '', 'fields' => '', 'ID' => '', 'number' => $noOfRecords, 'offset' => '', 'orderby' => 'comment_date_gmt', 'order' => 'DESC', 'post_ID' => '', 'post_id' => 0, 'post_name' => '', 'post_parent' => '', 'post_status' => '', 'post_type' => '', 'status' => 'approve',/* all- All , hold - unapproved comments,'approve' - approved comments 'spam' - spam comments 'trash' - trash comments 'post-trashed'*/ 'type' => '', 'count' => false, 'date_query' => null, // See WP_Date_Query ); return $postComments = get_comments( $defaults, OBJECT ); } function getArchivePost($instance){ $noOfRecords = $instance[ 'no_of_records' ]; $args = array( 'type' => 'monthly', 'limit' => $noOfRecords, 'format' => 'html', 'before' => '', 'after' => '', 'show_post_count' => true, 'echo' => 0, 'order' => 'DESC' ); return $archivePosts = wp_get_archives( $args, OBJECT ); } ?>