Skip to:
Content
Pages
Categories
Search
Top
Bottom

Add post featured image in activity stream

  • @shubh14

    Participant

    When I publish a new post to the blog all i get is ‘ADMIN wrote a new post, pictures 2 minutes ago’. I also want to show the post featured image in the stream. Can I do that?

Viewing 6 replies - 1 through 6 (of 6 total)
  • @danbp

    Participant

    hi @shubh14,

    please give some details about your configuration when you ask for help.

    WP/BP version, sigle or network install, theme name, used plugins.

    https://buddypress.org/support/topic/when-asking-for-support-2/

    @matt-mcfarland

    Participant

    Yes this is very easy to do.

    Adding the featured image of a wordpress post into a buddypress activity stream can be done by doing one of the following. I’d like to add that I had trouble finding out how to do this at first and it took a lot of searching. The first copypasta I have for you was actually found on these very forums. However, due to so many people asking this question (and not getting answers) it is buried and very difficult to find. So without further ado please enjoy…

    You can either edit the activity page activity/entry.php or just copy paste the following function into your functions.php file.

    
    function icondeposit_bp_activity_entry_meta() {
     
        if ( bp_get_activity_object_name() == 'blogs' && bp_get_activity_type() == 'new_blog_post' ) {?>
            <?php
            global $wpdb, $post, $bp;
            $theimg = wp_get_attachment_image_src(  get_post_thumbnail_id( bp_get_activity_secondary_item_id() ) );
            ?>
            <img src="<?php echo $theimg[0]; ?>" >
     
        <?php }
     
    }
    add_action('bp_activity_excerpt_append_text', 'icondeposit_bp_activity_entry_meta');
    

    If you want further customization, I recommend editing activity/entry.php

    @matt-mcfarland

    Participant

    Here’s MY entry.php file

    please don’t mind the bootstrap integration :p

    <?php
    
    /**
     * BuddyPress - Activity Stream (Single Item)
     *
     * This template is used by activity-loop.php and AJAX functions to show
     * each activity.
     *
     * @package BuddyPress
     * @subpackage bp-legacy
     */
    global $wpdb, $post, $bp;
    ?>
    
    <?php do_action( 'bp_before_activity_entry' ); ?>
    <?php echo $bp->current_item; ?>
    <li class="panel <?php bp_activity_css_class(); ?>" style="padding-top:0;" id="activity-<?php bp_activity_id(); ?>">
    	<div class="panel-heading" style="padding-top:0;">
    		<span class="activity-avatar">
    			<a href="<?php bp_activity_user_link(); ?>">
    				<?php bp_activity_avatar(); ?>
    			</a>
    		</span>
    			<?php bp_activity_action(); ?>
    	</div>
    	<div class="panel-body activity-content">
    		<?php if ( bp_activity_has_content() ) : ?>
    
    			<div class="activity-inner" >
    				<?php bp_activity_content_body();
    				
    				$blogpost_id = bp_get_activity_secondary_item_id();
    				if ($blogpost_id) :
    					if (has_post_thumbnail( $blogpost_id ) )	:
    						$theimg = wp_get_attachment_image_src( get_post_thumbnail_id( $blogpost_id ) ); ?>
    						<a href="<?php echo get_post_permalink($blogpost_id); ?>"> <img style="thumbnail" style="width:100%;" src="<?php echo $theimg[0]; ?>"></a>
    					<?php endif; ?>
    				<?php endif; ?>
    			</div>
    
    		<?php endif; ?>
    
    		<?php do_action( 'bp_activity_entry_content' ); ?>
    
    		<div class="activity-meta">
    			<?php if ( bp_get_activity_type() == 'activity_comment' ) : ?>
    
    				<a href="<?php bp_activity_thread_permalink(); ?>" type="button" class="button button-xs view" title="<?php _e( 'View Conversation', 'buddypress' ); ?>"><?php _e( 'All Comments', 'buddypress' ); ?></a>
    
    			<?php endif; ?>
    			<?php if ( is_user_logged_in() ) : ?>
    				<?php if ( bp_activity_can_comment() ) : ?>
    					<a href="<?php bp_activity_comment_link(); ?>" type="button" class="button button-xs acomment-reply"  id="acomment-comment-<?php bp_activity_id(); ?>"><i class="fa fa-comment"></i><?php printf( __( 'Comment <span>%s</span>', 'buddypress' ), bp_activity_get_comment_count() ); ?></a>
    				<?php endif; ?>
    				
    				<?php if ( bp_activity_can_favorite() ) : ?>
    
    					<?php if ( !bp_get_activity_is_favorite() ) : ?>
    
    						<a href="<?php bp_activity_favorite_link(); ?>" type="button" class="button button-xs fav"  title="<?php esc_attr_e( 'Mark as Favorite', 'buddypress' ); ?>"><i class="fa fa-thumbs-up"></i><?php _e( 'Favorite', 'buddypress' ); ?></a>
    
    					<?php else : ?>
    
    						<a href="<?php bp_activity_unfavorite_link(); ?>" class="button button-xs unfav bp-secondary-action"  title="<?php esc_attr_e( 'Remove Favorite', 'buddypress' ); ?>"><i class="fa fa-remove"></i><?php _e( 'UnFavorite', 'buddypress' ); ?></a>
    
    					<?php endif; ?>
    
    				<?php endif; ?>
    				
    				<?php if ( bp_activity_user_can_delete() ) {
    					echo '<a href="'.bp_get_activity_comment_delete_link().'" type="button" class="button button-xs item-button bp-secondary-action delete-activity confirm" rel="nofollow"><i class="fa fa-trash-o"></i>Remove</a>';
    					
    					} ?>
    				<?php do_action( 'bp_activity_entry_meta' ); ?>
    				
    			<?php endif; ?>
    		</div>
    
    	</div>
    
    	<?php do_action( 'bp_before_activity_entry_comments' ); ?>
    
    	<?php if ( ( is_user_logged_in() && bp_activity_can_comment() ) || bp_activity_get_comment_count() ) : ?>
    
    		<div class="activity-comments">
    
    			<?php bp_activity_comments(); ?>
    
    			<?php if ( is_user_logged_in() ) : ?>
    
    				<form action="<?php bp_activity_comment_form_action(); ?>" method="post" id="ac-form-<?php bp_activity_id(); ?>" class="ac-form"<?php bp_activity_comment_form_nojs_display(); ?>>
    					<div class="ac-reply-avatar"><?php bp_loggedin_user_avatar( 'width=' . BP_AVATAR_THUMB_WIDTH . '&height=' . BP_AVATAR_THUMB_HEIGHT ); ?></div>
    					<div class="ac-reply-content">
    						<div class="ac-textarea">
    							<textarea id="ac-input-<?php bp_activity_id(); ?>" class="ac-input" name="ac_input_<?php bp_activity_id(); ?>"></textarea>
    						</div>
    						<input type="submit" name="ac_form_submit" value="<?php _e( 'Post', 'buddypress' ); ?>" /> &nbsp; <a href="#" class="ac-reply-cancel"><?php _e( 'Cancel', 'buddypress' ); ?></a>
    						<input type="hidden" name="comment_form_id" value="<?php bp_activity_id(); ?>" />
    					</div>
    
    					<?php do_action( 'bp_activity_entry_comments' ); ?>
    
    					<?php wp_nonce_field( 'new_activity_comment', '_wpnonce_new_activity_comment' ); ?>
    
    				</form>
    
    			<?php endif; ?>
    
    		</div>
    
    	<?php endif; ?>
    
    	<?php do_action( 'bp_after_activity_entry_comments' ); ?>
    
    </li>
    
    <?php do_action( 'bp_after_activity_entry' ); ?>
    

    Fits with my theme, might not yours (my thumbnails are larger than default and I’m using a masonry layout) see it at http://www.hvac-hacks.com/activity

    @shubh14

    Participant

    @danbp Sorry about that. I am using WP 3.7.1, Buddypress 1.8.1, WP User Frontend. Single wordpress install.


    @matt-mcfarland
    thank you for your help. I added your code to functions file. however, out of three posts, I only see one with a visible attachment. See pic.
    screenshot

    P.S. You have a beautiful site..just a few issues. Activity page – the first buttons row is hidden behind the top header and the ‘members’ count shows 1 however, you have 1700+ members.
    activity page

    Single post page – the ‘login to reply’ link in comments aren’t visible as they are of the same color as the button bg
    buttons

    @matt-mcfarland

    Participant

    Thanks for your feedback! 😀

    I fixed the css issues you brought to my attention. Also fixed the number count (broke after updating to 1.9 beta, had to copy over legacy again to fix)

    As for only one image showing up in your activity feed that is strange, did you try editing entry.php?

    @shubh14

    Participant

    Thank you for your help. The code you provided shows post featured images however, how do I add pretty permalink to the images?
    this <a href="<?php echo get_post_permalink(bp_get_activity_secondary_item_id()); ?>"> returns <a href="http://localhost/mysite/?post_type=post&p=33">. However, I would like http://localhost/mysite/my-trip. I have a single wordpress installation.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Add post featured image in activity stream’ is closed to new replies.
Skip to toolbar