Skip to:
Content
Pages
Categories
Search
Top
Bottom

Adding classes to profile fields


  • applegateian
    Participant

    @applegateian

    Hi there

    I’m adding profile fields for members to add additional data to their profile.

    Some of these are checkboxes and the user can select more than one.

    What I want to do is give a unique class to each of the results that come back, to apply styles to these.

    There are four options for the user:

    And the markup returned is:

    I don’t seem to be able to add html to the profile fields or any other area. Is there a way to do this? I want to do something for each item like <div id="size500">£500K</div>

    Thanks,

    Ian

Viewing 7 replies - 26 through 32 (of 32 total)

  • applegateian
    Participant

    @applegateian

    Quick question @henrywright-1 – any way to give each of those that are spat out a unique id?

    Or do they have to have the same HTML around them?

    Ideally, each of the items are wrapped different id – e.g.

    
    <div id="size500">£500K</div>
    

    Henry
    Member

    @henrywright-1

    A unique ID is easy enough, just use the loop to output a unique value. e.g.

    
    $i = '1';
    if ( $items = bp_get_profile_field_data( array( 'field' => 'Budget' ) ) ) {
        foreach ( $items as $item ) { ?>
            <!-- put what you want here -->
            <?php echo 'item-' . $i; ?>
            <?php echo $item; ?>
            <?php $i++; ?>
            <!-- put what you want here -->
        <?php }
    }
    

    applegateian
    Participant

    @applegateian

    Hmm ok thanks @henrywright-1

    On the front end I get:

    item-1 £500k-£2m
    item-2 £2m+

    The HTML generated is –

    <div id="size500">        
     item-1        £500k-£2m        		
    </div>    
    <div id="size500">        
     item-2        £2m+        
    </div>    
    

    How can I make those divs unique?


    Henry
    Member

    @henrywright-1

    Ah I see what you’re trying to do.

    $i = '1';
    if ( $items = bp_get_profile_field_data( array( 'field' => 'Budget' ) ) ) {
        foreach ( $items as $item ) { ?>
            <div id="<?php echo 'size-' . $i; ?>">
            <?php echo $item; ?>
            </div>
            <?php $i++; ?>
        <?php }
    }

    shanebp
    Moderator

    @shanebp

    @henrywright-1

    Don’t initialize $i as a string if you’re going to use it as an integer.

    if ( $items = bp_get_profile_field_data( array( 'field' => 'Budget' ) ) ) {
        $i = 0;
        foreach ( $items as $item ) { ?>
            <div id="size-<?php echo ++$i; ?>">
            <?php echo $item; ?>
            </div>
        <?php }
    }

    applegateian
    Participant

    @applegateian

    Thanks @henrywright-1 and @shanebp

    Works a treat 🙂


    Henry
    Member

    @henrywright-1

    @shanebp good shout!

Viewing 7 replies - 26 through 32 (of 32 total)
  • The topic ‘Adding classes to profile fields’ is closed to new replies.
Skip to toolbar