Skip to:
Content
Pages
Categories
Search
Top
Bottom

Modifying "most active" widget for group-specific content


  • jcm10593
    Participant

    @jcm10593

    I’m trying to modify the various “most/recently active” topics/documents/etc widgets to display content from a specific group. It seems like it should be pretty straightforward to implement some kind of conditional statement i.e. “if document is associated with this group, display, if not, do nothing.” Currently I’m looking at the BuddyPress Docs Wiki “Most Active Wiki Pages” widget, mirrored below.

    I’m familiar with the bp_docs_get_associated_group_id() function, and looking at the bp_docs_has_docs() function, there appears to be some sort of built-in $d_group_id identifier, but I can’t figure out how to use them in this context. I have a Java background and this is my first foray into PHP. Any help or pointers about how to implement this is appreciated. I first tried to put a conditional in around line 55, but found myself lost regarding how, or on what object to call any kind of get_doc_id function.

    Thanks.

    /**
     * Most Active Wiki Pages
     */
    class BPDW_Most_Active_Widget extends WP_Widget {
    	public function __construct() {
    		parent::__construct(
    			'bpdw_most_active',
    			__( '(Wiki) Most Active Pages', 'bp-docs-wiki' ),
    			array(
    				'description' => __( 'A list of most active wiki pages.', 'bp-docs-wiki' )
    			)
    		);
    	}
    
    	public function form( $instance ) {
    		$defaults = array(
    			'title'     => __( 'Most Active', 'bp-docs-wiki' ),
    			'max_pages' => 5,
    		);
    		$instance = wp_parse_args( (array) $instance, $defaults );
    
    		$title     = strip_tags( $instance['title'] );
    		$max_pages = strip_tags( $instance['max_pages'] );
    
    		?>
    		<p><label for="<?php echo $this->get_field_id( 'title' ) ?>"><?php _e( 'Title:', 'bp-docs-wiki' ); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" style="width: 100%" /></label></p>
    		<p><label for="<?php echo $this->get_field_id( 'max_pages' ) ?>"><?php _e('Number of posts to show:', 'bp-docs-wiki'); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_pages' ); ?>" name="<?php echo $this->get_field_name( 'max_pages' ); ?>" type="text" value="<?php echo esc_attr( $max_pages ); ?>" style="width: 30%" /></label></p>
    		<?php
    	}
    
    	public function update( $new_instance, $old_instance ) {
    		$instance = $old_instance;
    
    		$instance['title']     = strip_tags( $new_instance['title'] );
    		$instance['max_pages'] = strip_tags( $new_instance['max_members'] );
    
    		return $new_instance;
    	}
    
    	public function widget( $args, $instance ) {
    		wp_enqueue_style( 'bp-docs-wiki-home', plugins_url() . '/buddypress-docs-wiki/wiki-home.css' );
    
    		extract( $args );
    		echo $before_widget;
    		echo $before_title
    		   . $instance['title']
    		   . $after_title;
    
    		$docs_args = array(
    			'posts_per_page' => $instance['max_pages'],
    			'orderby' => 'most_active',
    		);
    
    		$counter = 2; // Start with a weird number so as not to break the modulo
    		bp_docs_reset_query();
    		if ( bp_docs_has_docs( $docs_args ) ) {
    			echo '<ul>';
    			while ( bp_docs_has_docs() ) {
    				bp_docs_the_doc();
    				
    				$zebra = $counter % 2 ? 'odd' : 'even';
    				echo '<li class="' . $zebra . '">';
    				echo '<div class="wiki-page-title"><a href="' . get_permalink() . '">' . get_the_title() . '</a></div>';
    				echo '<div class="wiki-page-excerpt">' . get_the_excerpt() . '</div>';
    				echo '</li>';
    
    				$counter++;
    				
    		
    			}
    			echo '</ul>';
    		}
    
    		echo $after_widget;
    	}
    
    }
  • The topic ‘Modifying "most active" widget for group-specific content’ is closed to new replies.
Skip to toolbar