BuddyDev

Search

Can you help me with this snipprt

  • Participant
    frank on #27388

    I am using this snippet to show certain buddypress actvity on a page but it is showing full activity content , can you help me with the code which will limit the content to 120 0r 140 character.

    <?php
    $params = array(
    
    'user_id' => false,
    'scope' => false,
    'per_page' => 11,
    'action' =>'activity_update',
    'display_comments' => false,
    'meta_query' => array(
    array(
    'key' => 'favorite_count',
    'orderby' => 'meta_value',
    'meta_key' => 'favorite_count',
    'orderby'=> 'meta_value_num',
    'order' => 'DESC',
    )
    ),
    );
    
    if ( bp_has_activities( $params ) ) :?>
    
    <?php while ( bp_activities() ) : bp_the_activity();?>
    
    <a href="<?php bp_activity_user_link(); ?>">
    <?php bp_activity_avatar(); ?>
    <?php $member_id = bp_get_activity_user_id();
    echo '<div class="nono">' . bp_core_get_user_displayname( $member_id ) . '</div>';?>
    </a>
    
    <span class="activity">
    <?php printf( __( '%d Likes',  ), (int)bp_activity_get_meta( bp_get_activity_id(), 'favorite_count', true) ); ?><?php bp_activity_action(); ?>
    </span>
    </div>
    
    <a class="story__summary" href="<?php bp_activity_thread_permalink(); ?>"><?php bp_activity_content_body(); ?></a>
    
    <?php endwhile; ?>
    
    <?php endif;?>
  • Keymaster
    (BuddyDev Team)
    Posts: 21837
    Brajesh Singh on #27399

    Hi Frank,
    Welcome to BuddyDev.

    Please replace this line

    
    
    <a class="story__summary" href="<?php bp_activity_thread_permalink(); ?>"><?php bp_activity_content_body(); ?></a>
    
    

    with this

    
    
    <a class="story__summary" href="<?php bp_activity_thread_permalink(); ?>"><?php 
    echo bp_create_excerpt( bp_get_activity_content_body(), 140 ); ?></a>
    
    

    That should do it.

    Regards
    Brajesh

You must be logged in to reply to this topic.

This topic is: not resolved