BP_Core_Network_Posts_Widget::widget( array $args, array $instance )

Display the Members widget.

Description

See also

Parameters

$args

(array) (Required) Widget arguments.

$instance

(array) (Required) Widget settings, as saved by the user.

Source

File: bp-core/classes/class-bp-core-network-posts-widget.php

	public function widget( $args, $instance ) {

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

		/** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
		$title = apply_filters( 'widget_title', $settings['title'], $instance, $this->id_base );

		$number		 = (!empty( $instance[ 'number' ] ) ) ? absint( $instance[ 'number' ] ) : 5;
		$show_date	 = isset( $instance[ 'show_date' ] ) ? $instance[ 'show_date' ] : false;
		$show_image	 = isset( $instance[ 'show_image' ] ) ? $instance[ 'show_image' ] : true;

		if ( ! function_exists( 'get_sites' ) ){
		    return;
        }

		$blogs = get_sites(array(
            'fields' => 'ids',
            'orderby' => 'last_updated',
            'order' => 'DESC',
        ));

		$args['before_widget'];

		if ( $title ) {
            echo $args['before_title'] . $title . $args['after_title'];
        }

		if( $blogs ) {
		    ?> <ul id="network-list" class="item-list" aria-live="polite" aria-relevant="all" aria-atomic="true"> <?php
			foreach ( $blogs as $blog_key ) {
				switch_to_blog($blog_key);

				/**
				 * Filters the arguments for the Recent Posts widget.
				 *
				 * @since 3.4.0
				 *
				 * @see WP_Query::get_posts()
				 *
				 * @param array $args An array of arguments used to retrieve the recent posts.
				 */
				$r = new WP_Query( apply_filters( 'widget_network_posts_args', array(
					'posts_per_page'		 => $number,
					'no_found_rows'			 => true,
					'post_status'			 => 'publish',
					'ignore_sticky_posts'	 => true
				) ) );

				if ( $r->have_posts() ) { ?>
                    <?php while ( $r->have_posts() ) : $r->the_post(); ?>
                        <li class="vcard">
                            <div class="item-avatar">
                                <a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ), get_the_author_meta( 'user_nicename' ) ); ?>">
                                    <?php echo get_avatar( get_the_author_meta( 'ID' ), 80 ); ?>
                                </a>
                            </div>

                            <div class="item">
                                <div class="item-title">
                                    <a class="post-author" href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ), get_the_author_meta( 'user_nicename' ) ); ?>"><?php the_author(); ?></a>
                                    <span class="netowrk-post-type">created a post:</span>

                                </div>
                                <div class="item-data">
                            <span class="netowrk-post-content">
                                <a href="<?php the_permalink(); ?>" class="bb-title"><?php echo wp_trim_words( the_title( '', '', false ), 6, '&hellip;' ); ?></a>
                            </span>
                                    <?php if ( $show_image && has_post_thumbnail() ) { ?>
                                        <div class="data-photo"><a href="<?php the_permalink(); ?>"
                                                                   title="<?php echo esc_attr( sprintf( __( 'Permalink to %s', 'buddyboss' ), the_title_attribute( 'echo=0' ) ) ); ?>"
                                                                   class="entry-media entry-img">
                                                <?php the_post_thumbnail(); ?>
                                            </a>
                                        </div>
                                    <?php } ?>
                                    <?php if ( $show_date ) : ?>
                                        <br/><span class="netowrk-post-activity"><?php echo get_the_date(); ?></span>
                                    <?php endif; ?>
                                </div>
                            </div>
                        </li>
                    <?php endwhile; ?>
					<?php
					// Reset the global $the_post as this query will have stomped on it
					wp_reset_postdata();
				}
                // Back the current blog
				restore_current_blog();
			}
			?> </ul><?php
		}

		echo $args['after_widget'];

	}

Changelog

Changelog
Version Description
1.0.3 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.