This topic has 5 replies, 2 voices, and was last updated 10 years by Adam.

  • Author
  • #18770
     Adam
    Participant

    We’re going to show 4 active or popular members on the home page and I’m using the code below, but I need to limit the results to ONLY displaying users with a role of ‘subscriber’, as we have many editors, administrators and contributors who should not be included here ever.

    COPY CODE
    function kleo_top_members( $atts, $content = null ) {
    		extract(shortcode_atts(array(
    			'style' => 'standard'
    			), $atts));
    
        $output = '
        
        <div class="section-members">
            <div class="item-options" id="members-list-options">
              <a href="'.bp_get_members_directory_permalink().'" data-id="newest" class="members-switch">'.__("Newest", 'kleo_framework').'</a>
              <a href="'. bp_get_members_directory_permalink().'" data-id="active" class="selected members-switch">'.__("Active", 'kleo_framework').'</a>
              <a href="'.bp_get_members_directory_permalink().'" data-id="popular" class="members-switch">'.__("Popular", 'kleo_framework').'</a>
            </div>';
            
            $output .= '<ul class="item-list kleo-bp-active-members" style="display:none;">';
            if ( bp_has_members( 'type=active&max=4' ) ) :        
                while ( bp_members() ) : bp_the_member();                      
                $output .= mm_section_members_li();
    
                endwhile;
            endif;
            $output .='</ul>'; 
              
            $output .= '<ul class="item-list kleo-bp-newest-members" style="display:none;">';
            if ( bp_has_members( 'type=newest&max=4' ) ) :        
                while ( bp_members() ) : bp_the_member();                      
                $output .= mm_section_members_li();
    
                endwhile;
            endif;
            $output .='</ul>'; 
                
            $output .= '<ul class="item-list kleo-bp-popular-members" style="">';
            if ( bp_has_members( 'type=popular&max=4' ) ) :        
                while ( bp_members() ) : bp_the_member();                      
                $output .= mm_section_members_li();
    
                endwhile;
            endif;
            $output .='</ul>'; 
      
            $output .= '</div><!--end section-members-->';
            
    $output .= <<<JS
    <script type="text/javascript">
    jQuery(document).ready(function() {
        
        jQuery(".members-switch").click(function() {
            var bpMembersContext = jQuery(this).parent().parent();
            var container = "ul.kleo-bp-"+jQuery(this).attr('data-id')+"-members";
            
            jQuery("ul.item-list", bpMembersContext).hide();
            jQuery(".members-switch").removeClass("selected");
            jQuery(this).addClass("selected");
            jQuery(container, bpMembersContext).show(0, function() {
                jQuery(container+" li").hide().each(function (i) {
                    var delayInterval = 150; // milliseconds
                    jQuery(this).delay(i * delayInterval).fadeIn();
                });            
            });
            return false;
        }); 
    });
            
    jQuery(function () {
        jQuery('.kleo-bp-active-members').hide();
        jQuery('.section-members').one('inview', function (event, visible) {
          if (visible) {
              var container = ".kleo-bp-active-members";
              jQuery(container).show(0, function() {
                  jQuery(container+" li").hide().each(function (i) {
                      var delayInterval = 150; // milliseconds
                      jQuery(this).delay(i * delayInterval).fadeIn();
                  });            
              });
          }
        });
    
    });     
            
    </script>
    JS;
            return $output;
        
        } 
    add_shortcode('kleo_top_members', 'kleo_top_members');
    #18772
     Adam
    Participant

    I should say – I’m using BP 2.0 so is it easier to a custom bp loop other than the Top Members bp_parse_args instead of kleo_top_members?

    #18773
     Adam
    Participant

    so right now I’m just adding all of the admins/editors/contributors user ids to an &exclude= .. but this doesn’t seem ideal. So any shortcuts to a by-role solution would be appreciated!

    #19024
     Abe
    Keymaster

    Hi, see this gist and it could be a starting point for you https://gist.github.com/dzmounir/8285459

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    ---
    @ SeventhQueen we do our best to have super happy customers. Thanks for being our customer.

    #19026
     Adam
    Participant

    Yep – I found that and made a togglable plugin out of it. Should have updated this thread.. thanks!

    #19028
     Adam
    Participant

    Oh sorry this is the top-members thread. I’m still excluding by IDs there.

    I used that ^ link for the /members page..

    this forum reeeeeeallly needs and [edit] button D:

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.

Log in with your credentials

Forgot your details?