BuddyDev

Search

[Resolved] Adding Usernames to Gallery Listing

Tagged: ,

  • Participant
    Level: Initiated
    Posts: 3
    Kristin Tweedale on #10079

    Hello.

    I found this post – https://buddydev.com/support/forums/topic/add-member-name-membername-under-title-on-thumbs/ that seems to ask the exact same question I had.

    I have an all-galleries page at theawesomeladiesproject.com/gallery and I would like it to list the @ username of the member underneath the name of the gallery. I tried to put this code into my theme’s functions.php file and it didn’t seem to do anything.

    add_action( ‘mpp_after_media_widget_item’, ‘mpp_custom_add_user_link’ );
    function mpp_custom_add_user_link() {

    $user_id = mpp_get_media_creator_id();

    $link = sprintf( “%s“, bp_core_get_user_domain( $user_id ), bp_core_get_username( $user_id ) );

    echo $link;

    }

    Did mediapress change on the backend to make this solution not work anymore?

    Thanks.

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #10084

    Hi Kristin,
    Welcome to BuddyDev.

    Please use this snippet instead

    
    
    /**
     * Add @gallery-creator-username after the title
     */
    function mpp_custom_show_author_user_name_with_gallery() {
    	$gallery = mpp_get_gallery();
    
    	if ( ! $gallery ) {
    		return ;
    	}
    
    	echo '@' . bp_core_get_username( $gallery->user_id );
    }
    add_action( 'mpp_before_gallery_actions', 'mpp_custom_show_author_user_name_with_gallery' );
    

    You may modify it to suit your need.

    Hope that helps.

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 3
    Kristin Tweedale on #10124

    Thank you SO much Brajesh. That code works perfectly. I have one additional question.

    Members create galleries inside of private groups. The gallery listing page now displays everyone’s username, which is great. But when you click into a gallery, it doesn’t display there name anywhere at the top. Is there a short code snippet that I can add to insert a username display in the gallery title or description?

    Thank you!

    Kristin

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #10129

    Hi Kristin,
    Thank you.
    It’s a good idea and will like to have it in the core in future.

    For now, you may use the following code

    
    /**
     * Add @gallery-creator-username on single group gallery.
     */
    function mpp_custom_show_author_user_name_with_single_gallery() {
    	if ( ! bp_is_group() ) {
    		return ;
    	}
    
    	$gallery = mpp_get_gallery();
    
    	if ( ! $gallery ) {
    		return ;
    	}
    
    	echo '@' . bp_core_get_username( $gallery->user_id );
    }
    add_action( 'mpp_before_single_gallery', 'mpp_custom_show_author_user_name_with_single_gallery' );
    
    

    Hope that helps.

    Regards
    Brajesh

  • Participant
    Level: Master
    Posts: 163
    Audiomonk on #11629

    How do I get that username to link to their profile?

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #11640

    Hi Audiomonk,
    You can change this line

    
    echo '@' . bp_core_get_username( $gallery->user_id );
    

    to this

    
    
    printf( '@<a href="%s">%s</a>', bp_core_get_user_domain( $gallery->user_id ), bp_core_get_username( $gallery->user_id ) );
    
    

    PS: Please open a new topic and link to the existing one in future, that helps us server you better without causing any issue to the older threads. I hope you won’t mind that. It will help us avoid our existing thread users any inconvenience(notification etc).

    Thank you
    Brajesh

  • Participant
    Level: Master
    Posts: 163
    Audiomonk on #11713

    Ok thank you for the answer, I will do that in future.

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #11740

    Thank you.
    Brajesh

The topic ‘ [Resolved] Adding Usernames to Gallery Listing’ is closed to new replies.

This topic is: resolved