BBP_Topics_Widget::widget( array $args = array(), array $instance = array() )
Displays the output, the topic list
Description Description
Parameters Parameters
- $args
-
(Optional)
Default value: array()
- $instance
-
(Optional)
Default value: array()
Source Source
File: includes/common/widgets.php
public function widget( $args = array(), $instance = array() ) { // Get widget settings $settings = $this->parse_settings( $instance ); // Typical WordPress filter $settings['title'] = apply_filters( 'widget_title', $settings['title'], $instance, $this->id_base ); // bbPress filter $settings['title'] = apply_filters( 'bbp_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( // What and how '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' ) ), // Ordering 'orderby' => 'meta_value', 'order' => 'DESC', // Performance '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( // What and how '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' ) ), // Ordering 'orderby' => 'meta_value_num', 'order' => 'DESC', // Performance '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( // What and how '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'], // Ordering 'orderby' => 'date', 'order' => 'DESC', // Performance '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; } // Start an output buffer ob_start(); echo $args['before_widget']; if ( ! empty( $settings['title'] ) ) { echo $args['before_title'] . $settings['title'] . $args['after_title']; } ?> <ul class="bbp-topics-widget <?php echo esc_attr( $settings['order_by'] ); ?>"> <?php while ( $widget_query->have_posts() ) : $widget_query->the_post(); $topic_id = bbp_get_topic_id( $widget_query->post->ID ); $author_link = ''; // Maybe get the topic author if ( ! empty( $settings['show_user'] ) ) : $author_link = bbp_get_topic_author_link( array( 'post_id' => $topic_id, 'type' => 'both', 'size' => 14 ) ); endif; ?> <li> <a class="bbp-forum-title" href="<?php bbp_topic_permalink( $topic_id ); ?>"><?php bbp_topic_title( $topic_id ); ?></a> <?php if ( ! empty( $author_link ) ) : ?> <?php printf( esc_html_x( 'by %1$s', 'widgets', 'bbpress' ), '<span class="topic-author">' . $author_link . '</span>' ); ?> <?php endif; ?> <?php if ( ! empty( $settings['show_date'] ) ) : ?> <div><?php bbp_topic_last_active_time( $topic_id ); ?></div> <?php endif; ?> </li> <?php endwhile; ?> </ul> <?php echo $args['after_widget']; // Reset the $post global wp_reset_postdata(); // Output the current buffer echo ob_get_clean(); }
Changelog Changelog
Version | Description |
---|---|
2.0.0 | Introduced. |