Skip to:
Content
Pages
Categories
Search
Top
Bottom

Activity Stream Ads


  • tommyhares
    Participant

    @tommyhares

    Hello, is there an easy way of adding google adsens throughout the activity feed? It has to work with the ajax ‘Load More’ button in placing ads every 10th update. Thanks in advance to anyone who can help.

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

  • truelux
    Participant

    @truelux

    I’m looking for a solution to this as well.


    truelux
    Participant

    @truelux

    Here’s my solution… Place this into your child-theme’s / BuddyPress activity-loop.php

    <?php $number = 1;
    	while ( bp_activities() ) : bp_the_activity();
    	if ($number == 10){
    		echo 'ADSENSE_CODE_HERE';
    	}
    	$number++; ?>

    This makes the content appear after the first 10 activity streams but then it goes by every 20. Works for me though 🙂


    tommyhares
    Participant

    @tommyhares

    function activity_ads() {
      
      global $activities_template;
    
      $item_1 = $activities_template->activities[1];
      $item_11 = $activities_template->activities[11];
      $item_18 = $activities_template->activities[18];
      $item_26 = $activities_template->activities[26];
      $item_36 = $activities_template->activities[36];
      $item_46 = $activities_template->activities[46];
      $item_55 = $activities_template->activities[55];
      $item_65 = $activities_template->activities[65];
      $item_73 = $activities_template->activities[73];
      $item_92 = $activities_template->activities[92];
      $item_102 = $activities_template->activities[102];
      $item_127 = $activities_template->activities[127];
    
      if ( $item_1->id === $activities_template->activity->id || $item_11->id === $activities_template->activity->id || $item_18->id === $activities_template->activity->id || $item_26->id === $activities_template->activity->id || $item_36->id === $activities_template->activity->id || $item_46->id === $activities_template->activity->id || $item_55->id === $activities_template->activity->id || $item_65->id === $activities_template->activity->id || $item_73->id === $activities_template->activity->id || $item_92->id === $activities_template->activity->id || $item_102->id === $activities_template->activity->id || $item_127->id === $activities_template->activity->id ) { ?>
         
        <li class="ad">
          <div class="activity-content">
           
            <!-- Ad code here -->
            
          </div>
        </li>
          
      <?php }
      
    }
    add_action( 'bp_before_activity_entry', 'activity_ads' );

    Works if you need exact intervals.


    notright
    Participant

    @notright

    @tommyhares

    I tried this but it limited my ability to toggle between activity streams. For example when I went from “all members” to “friends” and the activity feed didn’t load. I have to refresh the page to get it to load. This is fine for a desktop but unworkable on a mobile.

    Any solution?

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
Skip to toolbar