'widget_thrive_tabs', 'description' => __( 'Up to 3 tabs with lists of posts or pages.', 'thrive' ) ); parent::__construct( 'widget_thrive_tabs', __( 'Thrive Tabs Widget', 'thrive' ), $widget_ops ); $this->alt_option_name = 'widget_thrive_tabs'; add_action( 'save_post', array( &$this, 'flush_widget_cache' ) ); add_action( 'deleted_post', array( &$this, 'flush_widget_cache' ) ); add_action( 'switch_theme', array( &$this, 'flush_widget_cache' ) ); add_action( 'wp_footer', array( &$this, '_js' ) ); } function widget( $args, $instance ) { if ( ! isset( $args['widget_id'] ) ) { $args['widget_id'] = "widget-thrive" . rand( 0, 999 ); } //by default the display of the post date should be on $instance['display_post_date'] = ( isset( $instance['display_post_date'] ) ) ? $instance['display_post_date'] : "on"; $instance['display_no_comments'] = ( isset( $instance['display_no_comments'] ) ) ? $instance['display_no_comments'] : "on"; $tabs_contents = $this->_build_tab_widget_contents( $instance ); $txt_class = ( $instance['thumbnail_size'] == "on" ) ? "" : " noImageTab"; ?>

    $label ): ?>
  • class="tS" style="width: %">
$contents ): ?>
style="display: block">

 
flush_widget_cache(); $alloptions = wp_cache_get( 'alloptions', 'options' ); if ( isset( $alloptions['widget_thrive_tabs'] ) ) { delete_option( 'widget_thrive_tabs' ); } return $instance; } function flush_widget_cache() { wp_cache_delete( 'widget_thrive_tabs', 'widget' ); } function form( $instance ) { $instance = wp_parse_args( (array) $instance, array( 'display_post_date' => 'on', 'display_no_comments' => 'on' ) ); $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; $trending_label = isset( $instance['trending_label'] ) ? esc_attr( $instance['trending_label'] ) : ''; $alltime_label = isset( $instance['alltime_label'] ) ? esc_attr( $instance['alltime_label'] ) : ''; $recent_label = isset( $instance['recent_label'] ) ? esc_attr( $instance['recent_label'] ) : ''; $category_label = isset( $instance['category_label'] ) ? esc_attr( $instance['category_label'] ) : ''; $custom_label = isset( $instance['custom_label'] ) ? esc_attr( $instance['custom_label'] ) : ''; $no_items_show = isset( $instance['no_items_show'] ) ? absint( $instance['no_items_show'] ) : 0; $thumbnail_size = isset( $instance['thumbnail_size'] ) ? ( $instance['thumbnail_size'] ) : ""; $trending_time = isset( $instance['trending_time'] ) ? absint( $instance['trending_time'] ) : 0; $display_post_date = isset( $instance['display_post_date'] ) ? ( $instance['display_post_date'] ) : "off"; $display_no_comments = isset( $instance['display_no_comments'] ) ? ( $instance['display_no_comments'] ) : "off"; $show_tabs_trending = isset( $instance['show_tabs_trending'] ) ? ( $instance['show_tabs_trending'] ) : ""; $show_tabs_popular = isset( $instance['show_tabs_popular'] ) ? ( $instance['show_tabs_popular'] ) : ""; $show_tabs_recent = isset( $instance['show_tabs_recent'] ) ? ( $instance['show_tabs_recent'] ) : ""; $show_tabs_category = isset( $instance['show_tabs_category'] ) ? ( $instance['show_tabs_category'] ) : ""; $show_tabs_menu = isset( $instance['show_tabs_menu'] ) ? ( $instance['show_tabs_menu'] ) : ""; $category = isset( $instance['category'] ) ? absint( $instance['category'] ) : 0; $mymenu = isset( $instance['menu'] ) ? absint( $instance['menu'] ) : 0; $first_tab = isset( $instance['first_tab'] ) ? $instance['first_tab'] : ""; $all_menus = get_terms( 'nav_menu', array( 'hide_empty' => true ) ); $menus_array = array(); foreach ( $all_menus as $menu ) { array_push( $menus_array, array( 'id' => $menu->term_id, 'name' => $menu->name ) ); } $all_categories = get_categories(); $categories_array = array(); foreach ( $all_categories as $cat ) { array_push( $categories_array, array( 'id' => $cat->cat_ID, 'name' => $cat->cat_name ) ); } ?>

checked="checked" class="thrive_chk_show_thumbnail"/>

checked="checked" class="thrive_chk_display_post_date" value="on"/>

checked="checked" class="thrive_chk_display_no_comments" value="on"/>


checked="checked" class="thrive_chk_show_tabs thrive_chk_show_trending"/>
checked class="thrive_chk_show_tabs thrive_chk_show_popular"/>
checked class="thrive_chk_show_tabs thrive_chk_show_recent"/>
checked class="thrive_chk_show_tabs thrive_chk_show_category"/>
checked class="thrive_chk_show_tabs thrive_chk_show_menu"/>

_get_trending_date( $instance['trending_time'] ); $r = new WP_Query( array( 'date_query' => array( array( 'after' => $date_params, ), ), 'order' => 'DESC', 'orderby' => 'comment_count', 'posts_per_page' => $limit_content, 'ignore_sticky_posts' => 1 ) ); $trending_posts = $r->get_posts(); $items_array = array(); foreach ( $trending_posts as $p ) { array_push( $items_array, array( 'title' => get_the_title( $p->ID ), 'url' => get_permalink( $p->ID ), 'date' => get_the_time( 'Y-m-d', $p->ID ), 'image' => $this->_get_featured_image( $p->ID ), 'no_comments' => get_comments_number( $p->ID ) ) ); } $items_array = array_slice( $items_array, 0, $limit_content ); $contents['trending'] = $items_array; } if ( $show_tabs_popular == "on" ) { $labels[] = isset( $instance['alltime_label'] ) ? ( $instance['alltime_label'] ) : __( 'Popular', 'thrive' ); $r = new WP_Query( array( 'order' => 'DESC', 'orderby' => 'comment_count', 'posts_per_page' => $limit_content, 'ignore_sticky_posts' => 1 ) ); $popular_posts = $r->get_posts(); $items_array = array(); foreach ( $popular_posts as $p ) { array_push( $items_array, array( 'title' => get_the_title( $p->ID ), 'url' => get_permalink( $p->ID ), 'date' => get_the_time( 'Y-m-d', $p->ID ), 'image' => $this->_get_featured_image( $p->ID ), 'no_comments' => get_comments_number( $p->ID ) ) ); } $items_array = array_slice( $items_array, 0, $limit_content ); $contents['popular'] = $items_array; } if ( $show_tabs_recent == "on" ) { $labels[] = isset( $instance['recent_label'] ) ? ( $instance['recent_label'] ) : __( 'Recent', 'thrive' ); $r = new WP_Query( array( 'orderby' => 'date', 'posts_per_page' => $limit_content, 'ignore_sticky_posts' => 1 ) ); $recent_posts = $r->get_posts(); $items_array = array(); foreach ( $recent_posts as $p ) { array_push( $items_array, array( 'title' => get_the_title( $p->ID ), 'url' => get_permalink( $p->ID ), 'date' => get_the_time( 'Y-m-d', $p->ID ), 'image' => $this->_get_featured_image( $p->ID ) ) ); } $items_array = array_slice( $items_array, 0, $limit_content ); $contents['recent'] = $items_array; } if ( $show_tabs_category == "on" && $instance['category'] > 0 ) { $labels[] = isset( $instance['category_label'] ) ? ( $instance['category_label'] ) : __( 'Category', 'thrive' ); $cat_posts = get_posts( array( 'category' => $instance['category'], 'posts_per_page' => $limit_content, 'numberposts' => $limit_content ) ); $items_array = array(); foreach ( $cat_posts as $p ) { array_push( $items_array, array( 'title' => get_the_title( $p->ID ), 'url' => get_permalink( $p->ID ), 'date' => get_the_time( 'Y-m-d', $p->ID ), 'image' => $this->_get_featured_image( $p->ID ) ) ); } $contents['category'] = $items_array; } if ( $show_tabs_menu == "on" && $instance['menu'] > 0 ) { $labels[] = isset( $instance['custom_label'] ) ? ( $instance['custom_label'] ) : __( 'Menu', 'thrive' ); $menu_items = wp_get_nav_menu_items( $instance['menu'] ); $items_array = array(); foreach ( (array) $menu_items as $key => $menu_item ) { $post_id = $menu_item->object_id; if ( $menu_item->object === 'category' ) { $category_posts = get_posts( array( 'category_name' => $menu_item->title, 'meta_query' => array( array( 'key' => '_thumbnail_id', 'compare' => 'EXISTS' ), ) ) ); $first_cat_post = current( $category_posts ); if ( $first_cat_post ) { $post_id = $first_cat_post->ID; } } array_push( $items_array, array( 'title' => $menu_item->title, 'url' => $menu_item->url, 'date' => get_the_time( 'Y-m-d', $menu_item->object_id ), 'image' => $this->_get_featured_image( $post_id ) ) ); } $items_array = array_slice( $items_array, 0, $limit_content ); $contents['menu'] = $items_array; } return array( 'labels' => $labels, 'contents' => $contents ); } function _get_featured_image( $postId ) { $featured_image_data = thrive_get_post_featured_image( $postId, "tt_post_icon" ); $featured_image = $featured_image_data['image_src']; return $featured_image; } // only load javascript when tabs widget is loaded. function _js() { if ( is_active_widget( false, false, $this->id_base, true ) ) { if ( wp_script_is( 'jquery' ) ) { ?> $myDate->format( "Y" ), 'm' => $myDate->format( "m" ), 'd' => $myDate->format( "d" ) ); } }