Skip to:
Content
Pages
Categories
Search
Top
Bottom

Dividing xprofile fields into groups in the profile-loop ?


  • Bowe
    Participant

    @bowromir

    Hi everyone,

    I’m trying to modify the profile-loop in such a way that I can call for certain groups and display them under different tabs.

    I want to have 3 tabs; Basic, Personal and Medical which shows the xprofile fields from those 3 categories. In the admin panel you can already create those groups, but how can I display them nicely on a profile seperated by tabs?

    A screenshot from what I have right now:

    http://www.bp-tricks.com/wp-content/uploads/tabs_profile.png

    So the question: how can I fill the other tabs with the content from the different profile groups?

    btw my current (modified) profile loop looks like this:

    <?php if ( function_exists('xprofile_get_profile') ) : ?>

    <?php if ( bp_has_profile() ) : ?>

    <?php while ( bp_profile_groups() ) : bp_the_profile_group(); ?>

    <?php if ( bp_profile_group_has_fields() ) : ?>

    <?php do_action( 'bp_before_profile_field_content' ) ?>

    <table class="profile-fields">
    <?php while ( bp_profile_fields() ) : bp_the_profile_field(); ?>

    <?php if ( bp_field_has_data() ) : ?>
    <tr<?php bp_field_css_class() ?>>

    <td class="label">
    <?php bp_the_profile_field_name() ?>
    </td>
    <td class="data">
    <?php bp_the_profile_field_value() ?>
    </td>

    </tr>
    <?php endif; ?>

    <?php do_action( 'bp_profile_field_item' ) ?>

    <?php endwhile; ?>
    </table>

    <?php do_action( 'bp_after_profile_field_content' ) ?>

    <?php endif; ?>

    <?php endwhile; ?>

    <?php do_action( 'bp_profile_field_buttons' ) ?>

    <?php else: ?>

    <p><?php _e( 'Sorry, this person does not have a public profile.', 'buddypress' ) ?></p>

    <?php endif;?>

    <?php else : ?>

    <?php bp_core_get_wp_profile() ?>

    <?php endif; ?>

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

  • John James Jacoby
    Keymaster

    @johnjamesjacoby

    I think to do this correctly, your loop will need a few more logic checks and error traps in the event that all of the info under a tab may be totally empty, or that some of the fields are empty and others are not. This might not be a problem if all of the fields are required, but you’ll need to modify the idea to taste. Example would be taking…

    <?php if ( bp_field_has_data() ) : ?> …and displaying something if the field actually is empty. Same with <?php if ( bp_profile_group_has_fields() ) : ?>

    I’d also check around the web for a lightweight JavaScript tab library, or do a quick Google for jQuery tabs and use the jQuery library that comes bundled with WP, and then follow the examples. I know there’s a few that just wrap the tabbed content in a container div and use an H3 or some other logical element as the clickable “tab.”

    Otherwise the code above should be sufficient to output the profile data into tables, you just need to find the engine to make your tabs go.


    Bowe
    Participant

    @bowromir

    Hi John,

    The tabs are already working and are powered by jQuery Tools (http://static.flowplayer.org/tools/). The JS only weighs 50kb and works a treat.. I’ve also used it for the welcome slider tut op BP-Tricks.com. See an example here: http://cfcommunity.net/FOK2009.

    I think I’m getting the idea (I can’t write php so this makes this all the more difficult) and if I understand correctly you can call the groups already under a different tab? How would I format the code for every tab?

    I’m guessing I need to modify

    <?php if ( bp_profile_group_has_fields() ) : ?>

    and say that *if user fills in something from profile group “medical” show it in this tab*. Right? haha sorry for asking me to basically spell it out for me, hope to get there some day :)


    vusis
    Participant

    @vusis

    This is great, the what i wanna do next is show certain tabs (profile groups) to different member levels.

    I saw there’s a function called profile_group_tabs. is there a way i can perhaps play around with this?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Dividing xprofile fields into groups in the profile-loop ?’ is closed to new replies.
Skip to toolbar