'forumax_recent_topics_widget widget_display_topics', 'description' => esc_html__('A list of recent topics, sorted by: newness, popularity, or recent replies.', 'forumax'), 'customize_selective_refresh' => true )); parent::__construct('forumax_recent_topics', esc_html__('(Forumax) Recent Topics', 'forumax'), $widget_ops); } /** * Register the widget */ public static function register_widget() { register_widget(__CLASS__); } /** * Displays the output, the topic list * * @param array $args Arguments * @param array $instance Instance */ public function widget($args = array(), $instance = array()) { wp_enqueue_style('bbpc-forum'); // Get widget settings $settings = $this->parse_settings($instance); // Typical WordPress filter $settings['title'] = apply_filters('widget_title', $settings['title'], $instance, $this->id_base); // Forumax filter $settings['title'] = apply_filters('forumax_topic_widget_title', $settings['title'], $instance, $this->id_base); // How do we want to order our results? switch ($settings['order_by']) { // Order by most recent replies case 'freshness': $topics_query = array( 'post_type' => bbp_get_topic_post_type(), 'post_status' => bbp_get_public_topic_statuses(), 'post_parent' => $settings['parent_forum'], 'posts_per_page' => (int) $settings['max_shown'], 'meta_query' => array( array( 'key' => '_bbp_last_active_time', 'type' => 'DATETIME' ) ), 'orderby' => 'meta_value', 'order' => 'DESC', 'ignore_sticky_posts' => true, 'no_found_rows' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false ); break; // Order by total number of replies case 'popular': $topics_query = array( 'post_type' => bbp_get_topic_post_type(), 'post_status' => bbp_get_public_topic_statuses(), 'post_parent' => $settings['parent_forum'], 'posts_per_page' => (int) $settings['max_shown'], 'meta_query' => array( array( 'key' => '_bbp_reply_count', 'type' => 'NUMERIC' ) ), 'orderby' => 'meta_value_num', 'order' => 'DESC', 'ignore_sticky_posts' => true, 'no_found_rows' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false ); break; // Order by which topic was created most recently case 'newness': default: $topics_query = array( 'post_type' => bbp_get_topic_post_type(), 'post_status' => bbp_get_public_topic_statuses(), 'post_parent' => $settings['parent_forum'], 'posts_per_page' => (int) $settings['max_shown'], 'orderby' => 'date', 'order' => 'DESC', 'ignore_sticky_posts' => true, 'no_found_rows' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false ); break; } // Note: private and hidden forums will be excluded via the // bbp_pre_get_posts_normalize_forum_visibility action and function. $widget_query = new WP_Query($topics_query); // Bail if no topics are found if (!$widget_query->have_posts()) { return; } echo $args['before_widget']; if (!empty($settings['title'])) { echo $args['before_title'] . $settings['title'] . $args['after_title']; } ?>
parse_settings($instance); ?>
esc_html__('Recent Topics', 'forumax'), 'max_shown' => 5, 'show_date' => true, 'show_user' => true, 'parent_forum' => 'any', 'order_by' => 'newness' ), 'forumax_topic_widget_settings'); } }