Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to pull a list of not_friends from the database ?


  • sixthgalaxy
    Participant

    @sixthgalaxy

    I want to show a list of not_friends in a widget. Can anyone please tell me how to show a list of not_friends with ‘add friends button’ in a custom widget?

Viewing 3 replies - 1 through 3 (of 3 total)

  • danbp
    Moderator

    @danbp

    not_friends are in fact members. Are you sure you want to built this, as such widget already exist ! Ok, has no Add Friend button…

    BuddyPress Widgets

    Another solution would be to use a shortcode who will fire a kind of Members widget and the add friend button. Huh ? 🙂

    Add this snippet to bp-custom.php

    function show_our_members( $atts ) {
    $user_id = bp_displayed_user_id();  
    
    /**
     * Options
     * type:active, newest, popular, online, alphabetical, random)
     * number:number of items
     * size:size of avatar in px
    */
    
    	$atts = shortcode_atts( array(
    		'type' => 'newest',
    		'number' => '10',		
    		'size' => '30'
    	), $atts, 'ourmembers' );
     
    if ( bp_has_members( 'type='.$atts['type'].'&max='.$atts['number'] ) ) :    
    
    	while ( bp_members() ) : bp_the_member(); ?>  
    
    		<ul><li class="vcard">
    			<div class="item-avatar">
    				<a>"><?php bp_member_avatar(); ?></a>
    			</div>
    
    			<div class="item">
    				<div class="item-title fn"><a>" title="<?php bp_member_name(); ?>"><?php bp_member_name(); ?></a></div>				
    				<div class="item-meta"><?php bp_add_friend_button( $user_id ); ?></div>			
    			</div>
    		</li></ul>
    <?php    
    endwhile;
    endif;
    }
    add_shortcode( 'ourmembers', 'show_our_members' );

    The shortcode to use (in post, pages, widgets…), eg. [ourmembers size=20 type=newest number=8]

    The only thing you have to do, is to style it accordingly to your theme layout.
    Note that the classes are those used in BP’s Members widget. You can use them or add your own.


    sixthgalaxy
    Participant

    @sixthgalaxy

    @danbp thank you for your reply.


    danbp
    Moderator

    @danbp

    You’re welcome! Is snippet working for you ?

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
Skip to toolbar