BBP_Forums_Widget::widget( mixed $args, array $instance )

Displays the output, the forum list

Description

Parameters

$args

(mixed) (Required) Arguments

$instance

(array) (Required) Instance

Source

File: bp-forums/common/widgets.php

	public function widget( $args, $instance ) {

		// Get widget settings
		$settings = $this->parse_settings( $instance );

		// Typical WordPress filter
		$settings['title'] = apply_filters( 'widget_title',           $settings['title'], $instance, $this->id_base );

		// Forums filter
		$settings['title'] = apply_filters( 'bbp_forum_widget_title', $settings['title'], $instance, $this->id_base );

		// 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( array(
			'post_type'           => bbp_get_forum_post_type(),
			//'post_parent'         => $settings['parent_forum'],
            'post_parent'         => 0,
			'post_status'         => bbp_get_public_status_id(),
			'posts_per_page'      => bbp_get_forums_per_page(),
			'ignore_sticky_posts' => true,
			'no_found_rows'       => true,
			'orderby'             => 'menu_order title',
			'order'               => 'ASC'
		) );

		// Bail if no posts
		if ( ! $widget_query->have_posts() ) {
			return;
		}

		echo $args['before_widget'];

		if ( !empty( $settings['title'] ) ) {
			echo $args['before_title'] . $settings['title'] . $args['after_title'];
		} ?>

		<ul class="bb-sidebar-forums">

			<?php while ( $widget_query->have_posts() ) : $widget_query->the_post(); ?>

				<li>
                    <a class="bbp-forum-title" href="<?php bbp_forum_permalink( $widget_query->post->ID ); ?>"><?php bbp_forum_title( $widget_query->post->ID ); ?></a>
                    <span class="topics-count">
                        <?php
                        $topics_count = bbp_get_forum_topic_count( $widget_query->post->ID );
                        echo $topics_count;
                        ?>
                    </span>
                    <?php
    				$r = array(
    						'before'              => '<ul class="bb-sidebar-forums">',
                            'after'               => '</ul>',
                            'link_before'         => '<li class="bbp-sub-forum">',
                            'link_after'          => '</li>',
    						'count_before'      => ' (',
    						'count_after'       => ')',
    						'count_sep'         => ', ',
    						'separator'         => ' ',
    						'forum_id'          => $widget_query->post->ID,
    						'show_topic_count'  => false,
    						'show_reply_count'  => false,
    					);

    				bbp_list_forums($r); ?>
                </li>

			<?php endwhile; ?>

		</ul>

		<?php echo $args['after_widget'];

		// Reset the $post global
		wp_reset_postdata();
	}

Changelog

Changelog
Version Description
bbPress (r2653) Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.