BuddyDev

Search

[Resolved] Display Images using BuddyPress XProfile plugin

  • Participant
    Level: Initiated
    Posts: 3
    Naveen on #35297

    How do I display image uploaded through Image Field at every place the buddypress avatar is displayed? I am creating a buddypress network of parents of handicapped children. I would like to display the child’s photo next to parent’s photo across the site. Kindly guide me on:

    1. How to access the image uploaded?
    2. How to display next to user photo?

    PS: I have posted this on wordpress.org but somehow it was marked as spam. I am reposting here for your support.

    thanks

  • Keymaster
    (BuddyDev Team)
    Posts: 24237
    Brajesh Singh on #35298

    Hi Naveen,
    Welcome to BuddyDev.

    1. You can access the image by using xprofile_get_field_data function.
    https://buddydev.com/fetching-and-showing-only-specific-fields-from-buddypress-xprofile-data/

    2. For this purpose, I will, suggest looking into the BuddyPress template pack’s code depending on whichever you are using.

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 3
    Naveen on #35325

    Thank you Brajesh for such a quick response. I found your advise to be very useful. I am able to get the desired output using the following code:

    echo xprofile_get_field_data( 'Child Profile Photo' , bp_get_member_user_id() );

    And then I am using this in nouveau template placing next to avatar image:

    	<div class="item-avatar">
    					<a href="<?php bp_member_permalink(); ?>">
    					    <?php bp_member_avatar( bp_nouveau_avatar_args() ); ?>
    					    <?php  echo xprofile_get_field_data( 'Child Profile Photo' , bp_get_member_user_id() ); ?>
    					    <?php buddyx_user_status( bp_get_member_user_id() ); ?></a>
    				</div>

    And then using CSS code, I am able to position it as overlay on the main profile photo of the user. I am able to achieve this using the class that the field provides (bpxcftr-image). something like this:

    /*childimage*/
    div.item-avatar .bpxcftr-image {
        width: 50px;
        position: absolute;
        bottom: 1px;
        right: 9px;
        border-radius: 50%;
    }

    Is there a possibility to specify our own class to a specific field in the function while rendering? For example, can I specify a class in this function:
    xprofile_get_field_data( 'Child Profile Photo' , bp_get_member_user_id(), 'EXAMPLE-CLASSNAME' )

    This will be useful if I have to use this function in different templates as each template has its own avatar sizes and I need to adjust them accordingly.

  • Keymaster
    (BuddyDev Team)
    Posts: 24237
    Brajesh Singh on #35356

    Hi Naveen,
    Thank you for the reply.
    Good to know that you were able to use it.

    You can not add css class to the image tag but you can wrap the generated image in an span and add your custom classes on that span.

    That should help you with achieving the desired result.

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 3
    Naveen on #35410

    Thank you Brajesh. Yes, I am wrapping it in a div and adding custom class. It is working but image filed is showing up only on the Profile’s Activity Stream but not on Site wide Activity Stream. In fact, it is only outputting the wrapped div element and the class. But the image field output is not echoed at all. The outputted html that I could grab from the browser is as follows:

    
     <div class="activity-avatar item-avatar">
                <a href="https://anvay.online/members/anvay/">
                    <img loading="lazy" src="//www.gravatar.com/avatar/1c7825a86f453ea56735a31959bbd4b0?s=150&r=g&d=mm" class="avatar user-1-avatar avatar-150 photo" width="150" height="150" alt="Profile picture of anvay">                
                    <div class="activity-child-photo"></div>
                </a>
     </div>
    
    

    As you have noticed <div class="activity-child-photo"></div> does not have any img element inside it. However, on Member’s page if I go to the Activity tab, then the img element is getting outputted as follows:

    
            <div class="activity-avatar item-avatar">
                <a href="https://anvay.online/members/anvay/">
                    <img loading="lazy" src="//www.gravatar.com/avatar/1c7825a86f453ea56735a31959bbd4b0?s=150&r=g&d=mm" class="avatar user-1-avatar avatar-150 photo" width="150" height="150" alt="Profile picture of anvay">
                    <div class="activity-child-photo"><img src="https://anvay.online/wp-content/uploads/bpxcftr-profile-uploads/1/image/2.png" alt="" class="bpxcftr-image"></div>
                </a>
            </div>
    
    

    My code is as follows in the file: wp-content/themes/buddyx-child/buddypress/activity/entry.php

    
    <div class="activity-avatar item-avatar">
                <a href="<?php bp_activity_user_link(); ?>">
                    <?php bp_activity_avatar( array( 'type' => 'full' ) ); ?>
                    <div class="activity-child-photo"><?php  echo xprofile_get_field_data( 'Child Profile Photo' , bp_get_member_user_id() ); ?></div>
                </a>
    </div>
    

    Where am I going wrong? How do I get same result in site wide Activity and individual activity page?

    thanks,
    Naveen

  • Keymaster
    (BuddyDev Team)
    Posts: 24237
    Brajesh Singh on #35426

    Hi,
    You will need to use different functions for providing user id.

    In case of the activity, you should replace this

    
    bp_get_member_user_id()
    

    by

    
    bp_get_activity_user_id()
    

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 3
    Naveen on #36108

    Thank you Brajesh. This works perfectly fine. Thanks for the excellent support. I would like to buy one of your plugins (Friend Suggestion Pro) and may be request you for some custom development. I will PM you.

  • Keymaster
    (BuddyDev Team)
    Posts: 24237
    Brajesh Singh on #36113

    Thank you Naveen.

The topic ‘ [Resolved] Display Images using BuddyPress XProfile plugin’ is closed to new replies.

This topic is: resolved