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 12 replies - 1 through 12 (of 12 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?


    iamdev
    Participant

    @iamdev

    Any one how to make @tommyhares code work. it is working but has little problem as @notright mentioned here. i think everyone would like to see that work


    Venutius
    Moderator

    @venutius

    I tried truelux’s code in the Nouveau activity-loop and that seems to work fine even when switching streams, why not use that? The key to it is to make sure you over-write the existing while ( bp_activities() ) : bp_the_activity(); which that code to get it working.


    iamdev
    Participant

    @iamdev

    i tried trulux code but problem still exist 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. as mentioned by notright. i cannot use nouveau because my theme donot support it.


    Venutius
    Moderator

    @venutius

    For me it works, both on Legacy and on Nouveau


    iamdev
    Participant

    @iamdev

    ya i know it is working but has some problem as mentioned by @notright


    Venutius
    Moderator

    @venutius

    I can switch between views and it still works


    iamdev
    Participant

    @iamdev

    i couldn’t configure what is the problem,if it is working on your side then may be i have problem with my theme


    iamdev
    Participant

    @iamdev

    the problem started when you ad your ads script code

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