Skip to:
Content
Pages
Categories
Search
Top
Bottom

Forum Replies Created

Viewing 1 replies (of 1 total)

  • lomaymi
    Participant

    @lomaymi

    Thanks danbp for your help, it really point me in the right direction. I decided to use post_excerpt instead of the_content because that one proved quite problematic. The post excerpt worked wonderfully!! Here is the fixed code for anyone to use as reference (note that I also added feature image, post url and a read more button):

    <?php
    
    // Edits how blog posts appears on activity feed.
    
    function bp_posts_in_activity_feed( $content, $activity ) {
    
         if ( 'new_blog_post' == $activity->type ) {
    
            $post = get_post( $activity->secondary_item_id );
    
         if ( 'post' == $post->post_type )
                 $title = isset( $post->post_title ) ? $post->post_title : '';
                 $before_author = 'By';
                 $author = get_userdata( $post->post_author )->user_nicename;
                 $content = get_post( $post->ID )->post_excerpt;
                 $feature_img = wp_get_attachment_image( get_post_thumbnail_id($post->ID), $size ='medium' );
                 $post_url = get_permalink($post->ID);
                 $read_more = "<button type='button'>Read More</button>";
                
         }
        
        echo "<a href='$post_url'><h2 align=center>" .$title. "</h2></a>";
        echo "<h5 align=center>" .$before_author . ' ' . $author. "</h5>";
        echo "<a href='$post_url'><div align=center>" .$feature_img. "</div></a>";
        echo "<p>" .$content. "</p>";
        echo "<a href='$post_url'><h3 align=right>" .$read_more. "</h3></a>";
        
         
    }    
    add_filter( 'bp_get_activity_content_body', 'bp_posts_in_activity_feed', 10, 2 );

    I wanted to point out that on your reply above you suggested…

    echo '<h5 align=center>By '. $author .'</h5>';

    to show the author, but with that method the text “By” appeared above every single entry in the SWA. To fix that I just added the “By” text on a variable and then combined them on the echo. That way it only appears if there is a new blog post.

Viewing 1 replies (of 1 total)
Skip to toolbar