This topic has 2 replies, 2 voices, and was last updated 9 years by Miriam.

  • Author
  • #50962
     Miriam
    Participant

    Hello,
    I want to give out a profile-field (called “Gesuchstext”) on my homepage. Some users have very long text in this field, so I would like to shorten it on 100 characters on my homepage.
    I worked in the bp_members_masonry.php (k-elements > shortcodes > buddypress)

    I tried it with the php-functions
    echo substr(bp_member_profile_data( ‘field=Gesuchstext’ ),0,100);

    and

    echo mb_strimwidth(bp_member_profile_data( ‘field=Gesuchstext’ ),0,100, “…”);

    But both of them seemed to be ignored. Could you please check my code?

    Thanks a lot & greetings from Berlin
    Miriam

    COPY CODE
    <?php
    /**
     * Buddypress Members masonry
     * 
     * 
     * @package WordPress
     * @subpackage K Elements
     * @author SeventhQueen <themesupport@seventhqueen.com>
     * @since K Elements 1.0
     */
     
    
    $output = '';
    extract(
    	shortcode_atts( array(
    		'type' => 'newest',
    		'number' => 12,
    		'class' => '',
    		'rounded' => "rounded",
    		'online' => 'show'
    	), $atts ) 
    );
    
    $params = array(
    	'type' => $type,
    	'per_page' => $number
    );
    if ($rounded == 'rounded') {
    	$rounded = 'rounded';
    }
    if ( function_exists('bp_is_active') ) {
    	if ( bp_has_members( $params ) ){
    		ob_start();
    		echo '<div class="wpb_wrapper">';
    		echo '<div id="members-dir-list" class="members dir-list">';
    		echo '<ul id="members-list" class="item-list row kleo-isotope masonry '.$class.'">';
    		
    		while( bp_members() ) : bp_the_member();
    
    		
    			echo 	'<li class="kleo-masonry-item">'
    					.'<div class="member-inner-list animated animate-when-almost-visible bottom-to-top">'
    					 .'<div class="item-avatar '.$rounded.'">'
    							.'<a href="'. bp_get_member_permalink().'">'. bp_get_member_avatar() . kleo_get_img_overlay() . '</a>';
    							if ($online == 'show') {
    								echo kleo_get_online_status(bp_get_member_user_id());
    							}
    						echo '</div>'
    						
    
    					.'<div class="item">
    							<div class="item-title">'
    								.'<a href="'. bp_get_member_permalink().'">'. bp_get_member_name() . '</a>
    							</div>
    					<div class="item-meta"><span class="activity">'.bp_get_member_last_active().'</span></div>';
    
    						echo '</div>';
    					if ( bp_get_member_latest_update() ) {
    						echo '<span class="update"> '. bp_get_member_latest_update().'</span>';
    					}
    					
    					/*do_action( 'bp_directory_members_item' );*/
    					  echo '<div class="update">';
    					  echo 'Aus: ';
    					  echo bp_member_profile_data('field=Stadt'); 
    					  echo ' (';
    					  echo bp_member_profile_data('field=Bundesland');
    					  echo ') ';
    					  echo '<br>';
    					  echo 'Rolle: ';
    					  echo bp_member_profile_data('field=Rolle');
    					  echo '</div>';
    					  echo '<hr>';
    					  echo '<div class="ellipsis">';
    					  echo bp_member_profile_data( 'field=Gesuchstext' );
    					  echo '</div>';
    					echo '<!--end member-inner-list-->
    				</li>';
    		endwhile;
    		
    		echo '</ul>';
    		echo '</div>';
    		echo '</div>';
    		$output = ob_get_clean();
    	}
    
    }
    else
    {
    	$output = __("This shortcode must have Buddypress installed to work.","kleo_framework");
    } 
    
    #51705
     sharmstr
    Moderator

    2 Things. Use bp_get_member_profile_data instead: substr(bp_get_member_profile_data( ‘field=Gesuchstext’ ),0,100);

    Also, instead of editing the php files, just inject it.

    COPY CODE
    
    add_action('bp_directory_members_item','add_member_fields');
    function add_member_fields() {
    	echo '<div class="update">';
    	echo 'Aus: ';
    	echo bp_member_profile_data('field=Stadt'); 
    	echo ' (';
    	echo bp_member_profile_data('field=Bundesland');
    	echo ') ';
    	echo '<br>';
    	echo 'Rolle: ';
    	echo bp_member_profile_data('field=Rolle');
    	echo '</div>';
    	echo '<hr>';
    	echo '<div class="ellipsis">';
    	echo substr(bp_get_member_profile_data( 'field=Gesuchstext' ),0,100);
    	echo '</div>';
    	echo '<!--end member-inner-list-->';	
    	
    }
    
    
    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    This support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com

    #52295
     Miriam
    Participant

    It works, thanks a lot!!

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

The forum ‘Plugins questions’ is closed to new topics and replies.

Log in with your credentials

Forgot your details?