Skip to:
Content
Pages
Categories
Search
Top
Bottom

Blending Posts into Activity


  • tommyhares
    Participant

    @tommyhares

    Hello, I am working on a pretty big project that requires psots to be inserting in every 5th or so slot of the Activity feed. Is there a way to automate this or is there a function I can use to cycle through my posts and insert into the feed? Any help is greatly appreciated!

Viewing 5 replies - 1 through 5 (of 5 total)

  • modemlooper
    Moderator

    @modemlooper

    heres some starter code

    function custom_markup_before_every_fifth_activity() {
    	global $activities_template;
    
    	$item_5 = $activities_template->activities[4];
    
    	if ( $item_5->id === $activities_template->activity->id ) {
    
    		echo '<li>';
    			echo '<div class="activity-content">';
    				echo 'place add code here';
    			echo '</div>';
    		echo '</li>';
    	}
    };
    add_action( 'bp_before_activity_entry', 'custom_markup_before_every_fifth_activity' );

    tommyhares
    Participant

    @tommyhares

    Thanks for that. I tried writing a for loop using the modulus operator for every 5th post, but it doesn’t seem to be working. Is there a better way to do this?


    modemlooper
    Moderator

    @modemlooper

    Fifth post? here’s what code looks like


    tommyhares
    Participant

    @tommyhares

    Yes, it has to be every 5th update. so the 5th, 10th, 15th and so on… I can’t get it to loop through that way. I appreciate your help.


    modemlooper
    Moderator

    @modemlooper

    I’m still confused, the code I gave you will add content above every 5th item. when you click load more it adds to the 5th item in the response.

    If you have 20 items and you want every 5th item. then you can check array

    function custom_markup_before_every_fifth_activity() {
    	global $activities_template;
    
    	$items = array(
    		$activities_template->activities[4]->id,
    		$activities_template->activities[9]->id,
    		$activities_template->activities[14]->id,
    	);
    
    	if ( in_array( $activities_template->activity->id, $items, true ) ) {
    		echo '<li>';
    			echo '<div class="activity-content">';
    				echo 'place add code here';
    			echo '</div>';
    		echo '</li>';
    	}
    };
    add_action( 'bp_before_activity_entry', 'custom_markup_before_every_fifth_activity' );
Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.
Skip to toolbar