Skip to:
Content
Pages
Categories
Search
Top
Bottom

Profile Field adds Award


  • Nick Watson
    Participant

    @nickbwatson

    I’m looking for a way that depending on what my user selects in their profile, it will display a badge, or something in their profile.

    Also, how may I access the profile fields when designing my profile. I mean, I don’t want all of the things to fall under that chart, I’d like to move a few of them into other locations.

    Thanks

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

  • Nick Watson
    Participant

    @nickbwatson

    Also, how can I get it so that when I make a checkbox profile field, it displays them in a list.

    What it’s doing:

    Red [ ] Blue [ ] Green [ ] Yellow [ ]

    What I want:

    Red [ ]

    Blue [ ]

    Green [ ]

    Yellow [ ]


    Nick Watson
    Participant

    @nickbwatson

    I think people are starting to get tired of me asking questions.

    Anyway, to restate my major problem, without making a new topic altogether:

    I’ve created a profile field (checkboxes) and in that there are 4 selections. User A comes on and selects Red and Green. On his profile I’d like a Red Badge, and a Green Badge to appear on his profile.

    Is there a way I can do this?


    Boone Gorges
    Keymaster

    @boonebgorges

    In [your-bp-theme-dir]/members/single/profile/profile-loop.php, you’ll see a profile loop beginning while ( bp_profile_fields() ) : bp_the_profile_field();. Inside of that profile loop you will be able to use various profile functions to test values. For instance,

    <?php if ( bp_the_profile_field_name() == 'color' ) {
    if ( bp_the_profile_field_value() == 'red' )
    echo '<img src="redbadge.png" />';
    if ( bp_the_profile_field_value() == 'green'
    echo '<img src="greenbadge.png" />';
    // etc.
    }
    ?>

    I have not tested this but it should work fine with some tweaking.

    Your issue with appearance is a CSS thing, most likely that the ul elements are set to display: inline. Try setting them to display: block.


    Nick Watson
    Participant

    @nickbwatson

    Ahh, well that looks a lot nicer when I changed the css to block.

    Thank you.

    But maybe I’m doing something wrong with the code. Or maybe I’m entering the wrong field name or field value.

    But nothing really seems to happen.


    Boone Gorges
    Keymaster

    @boonebgorges

    The code that I listed will not work as is. You have to make sure that you fill in the correct filenames for images, the correct desired values for profile fields, and the correct field names. Also it looks like I messed up and forgot at least one parenthesis. That’s why I said you’d need to tweak it. It should give you an idea of which functions to use, though.


    Nick Watson
    Participant

    @nickbwatson

    Oh yeah, I changed the image, fieldnames and values, and I added the parenthesis on the end of the ‘green’ line, but it still doesn’t seem to do anything, is it because I’m using checkboxes?


    Boone Gorges
    Keymaster

    @boonebgorges

    Could be. You might want to try echoing bp_the_profile_field_value() to see what’s popping out for different cases.


    Nick Watson
    Participant

    @nickbwatson

    bp_the_profile_field_value displays ALL of the values of the fields within the group, and

    bp_the_profile_field_name displays ALL of the names of the fields within the group.

    I tried what you said with the <?php if ( bp_the_profile_field_name() == ‘color’ ) {

    but that still just continues to display ALL of the fields. (And yes I changed the ‘color’ to the proper field name)

    Anyone have ideas on how to get a profile fields output to display a picture instead of the text?


    Boone Gorges
    Keymaster

    @boonebgorges

    Oops, my bad. I gave you the echo functions when you need the non-echoing ones. This works, I just tested it.:

    if ( bp_get_the_profile_field_name() == 'color' ) {
    if ( bp_get_the_profile_field_value() == 'green' )
    echo '<img src="green.png" />';
    }


    Nick Watson
    Participant

    @nickbwatson

    I trust your code works, but I think I just have no idea what I’m doing.

    This is what my code looks like:

    <br />
    <?php while ( bp_profile_fields() ) : bp_the_profile_field(); ?><br />
    <?php if ( bp_get_the_profile_field_name() == 'Gender' ) {<br />
    if ( bp_get_the_profile_field_value() == 'Male' )<br />
    echo '<img src="male.jpg" alt="male" title="Male" />';<br />
    }<br />
    ?><br />
    etc etc etc<br />
    rest of the code<br />

    (I’ve tried with both lowercase and uppercase fields)

    I’m just using the Gender one to test this out, I’ve tested it with all these other ones but none of them are working.

    What am I doing wrong.


    Nick Watson
    Participant

    @nickbwatson

    By the way, I have no idea why there are all those breaks. Ignore all the breaks in the code:

    this is the real code

    <?php while ( bp_profile_fields() ) : bp_the_profile_field(); ?>
    <?php if ( bp_get_the_profile_field_name() == 'Gender' ) {
    if ( bp_get_the_profile_field_value() == 'Male' )
    echo '<img src="male.jpg" alt="male" title="Male" />';
    }
    ?>
    etc etc etc
    rest of the code


    Boone Gorges
    Keymaster

    @boonebgorges

    Are you putting it inside of the default profile-loop.php file? Could you paste the whole contents of that file here or in pastebin with a link?


    Nick Watson
    Participant

    @nickbwatson

    Yeah it’s the original profile-loop.php file.

    http://pastebin.com/m607c4e2b

    Thanks for all the help.


    Boone Gorges
    Keymaster

    @boonebgorges

    Thanks for pasting up that code. I think I found the issue. It has to do with the way that content returned by bp_get_the_profile_field_name has filters applied to it, namely the filters that some profile field items into links. There are a couple ways around the problem, but the easiest is to get the data before the filters hit. Thus:

    <?php if ( bp_get_the_profile_field_name() == 'Gender' ) {
    global $field;
    if ( bp_unserialize_profile_field( $field->data->value ) == "Male" )
    echo '<img src="male.jpg" alt="male" title="Male" />';
    }
    ?>

    I didn’t experience this in my test because (I think) my field data came from a textarea rather than a radio button. But the strategy I just gave you should be safe in any case.

    Hope it works!


    Nick Watson
    Participant

    @nickbwatson

    YES! Thank you very much. This has been a painful process for you I’m sure.

    Thanks!


    Nick Watson
    Participant

    @nickbwatson

    Hmm, not a huge issue.

    But how could I get this to work with.. checkboxes.

    Right now when someone selects Red, it will show up with a red picture, but if they also select green, then nothing shows up (because the value is no longer just “Red”)

    Just curious, this isn’t a huge issue


    Boone Gorges
    Keymaster

    @boonebgorges

    Glad it works!

    Well, checkboxes will be a little trickier because of the possibility of multiple selections. You could try something like:

    <?php if ( bp_get_the_profile_field_name() == 'color' ) {
    global $field;
    $value = bp_unserialize_profile_field( $field->data->value );
    $value = explode( ", ", $value);
    if ( in_array( 'red', $value ) )
    echo '<img src="red.jpg" alt="red" title="red" />';
    if ( in_array( 'green', $value ) )
    echo '<img src="green.jpg" alt="green" title="green" />';
    }
    ?>


    Nick Watson
    Participant

    @nickbwatson

    You’ve been a huge help. I can’t thank you enough.


    zoltok
    Participant

    @zoltok

    How would something like this be adapted for the directory loop? Is it possible? I am hoping to show whether users have a particular checkbox ticked in their profile (for the same purpose, to show a “badge”).

Viewing 19 replies - 1 through 19 (of 19 total)
  • The topic ‘Profile Field adds Award’ is closed to new replies.
Skip to toolbar