BuddyDev

Search

Activity ads adjustment

  • Participant
    Level: Guru
    Posts: 662
    Tosin on #38837

    Hello,

    How can I make your code to display only once on first page load and not repeatedly after subsequent ajax load of ‘n’ activities.

     /**
     * Inject content into BuddyPress Activity stream after 'n' activities.
     */
    function buddydev_inject_content_after_n_activities() {
        static $current_activity_index = 1;
     
        // change $n to the correct number of activities.
        $n = 5; // After how many activities you want to inject content.
     
        if ( $current_activity_index % $n === 0 ) {
            ?>
            <li class='activity-item activity-ad-item activity-custom-entry'>
               <?php echo do_shortcode('[ADVERT CODE]'); ?>
            </li>
            <?php
            // show the activity injected content.
        }
        // increment the current index.
        $current_activity_index ++;
     
    }
    add_action( 'bp_after_activity_entry', 'buddydev_inject_content_after_n_activities' ); 
  • Keymaster
    (BuddyDev Team)
    Posts: 21520
    Brajesh Singh on #38838

    Hi Tosin,
    Please search the forum for similar issue/topic. I have mentioned the problem with limiting the ads.
    I regret my inability to assist you with this specific use case.

    Regards

    Brajesh

You must be logged in to reply to this topic.

This topic is: not resolved