Skip to:
Content
Pages
Categories
Search
Top
Bottom

How can i place ad code after every 5 activities in buddy press Activity Loop?


  • muraliniceguy97
    Participant

    @muraliniceguy97

    I tried to display ad code in buddy press every 5 activities. Can any one suggest me to create.

    <?php while ( bp_activities() ) : bp_the_activity(); ?>     
    
        <?php bp_get_template_part( 'activity/entry' );   ?>    
    
        <?php 
    
             $count = bp_get_activity_count(); 
             for ( $i = 1; $i < $count; $i++ ) {            
            if ( $i % 8 == 0 ) {                        
    
        ?>       
    
            <?php the_ad(3860); ?>
    
        <?php   } ?>        
    
        <?php } ?>
    
    <?php endwhile; ?>
Viewing 1 replies (of 1 total)

  • Henry Wright
    Moderator

    @henrywright

    Not sure you need that custom for loop. Also, an alternative to using the modulo operator is to reset the counter. Take a look at this as an example:

    // Init the counter.
    $i = 0;
    
    // Begin activity loop here.
    
    // Increment the counter by 1.
    $i = ++$i;
    
    // Check if we're in the 8th iteration.
    if ( 8 === $i ) {
        // Output ad code here.
    
        // Reset the counter.
        $i = 0;
    }
    
    // End activity loop here.
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.
Skip to toolbar