Skip to:
Content
Pages
Categories
Search
Top
Bottom

Forum Replies Created

Viewing 9 replies - 1 through 9 (of 9 total)
  • @tommyhares

    Participant

    Yes, hat code did work however it was using a static ad code. I am looking to iterate through posts every 7th slot for this project. Thank you for assisting me.

    @tommyhares

    Participant

    How do I do that on the server side? Or did you mean client-side?

    @tommyhares

    Participant

    Thanks again for your help Henry. I tried your additions, however the counter still gets reset to 0 after the Load More gets initiated

    @tommyhares

    Participant

    I assume I have to use the JS ajaxComplete() and run an increment to pass back to the php

    @tommyhares

    Participant
    do_action( 'bp_before_activity_loop' ); ?>
    
    <?php if ( bp_has_activities( bp_ajax_querystring( 'activity' ) ) ):
    
      if ( empty( $_POST['page'] ) ) : ?>
    
        <ul id="activity-stream" class="activity-list item-list">
    
      <?php endif; ?>
    
      <?php      
        $count = 0;
    
        $args = array(
          'posts_per_page'   => 100000,
          'offset'           => 0,
          'category'         => '',
          'category_name'    => 'freedom-friend-news',
          'order'            => 'desc',
          'orderby'          => 'date',
          'include'          => '',
          'exclude'          => '',
          'meta_key'         => '',
          'meta_value'       => '',
          'post_type'        => 'post',
          'post_mime_type'   => '',
          'post_parent'      => '',
          'author'	         => '',
          'author_name'	     => '',
          'post_status'      => 'publish',
          'suppress_filters' => true 
        );
        $news_articles = get_posts( $args ); 
              
    	while( bp_activities() ): bp_the_activity();
    
    		bp_get_template_part( 'activity/entry' );
              
            $current_user = wp_get_current_user();
            if( $current_user->user_login == 'tommy' ):
              
              $count++;
              $news_iteration = $count / 7)-1;
              
              // Loop through news articles as long as there are articles.
              if( $count % 7 == 0 && !empty( $news_articles[$news_iteration] )):
              
                echo 'News Article';
                echo 'Iteration: '.$news_iteration;
                echo $news_articles[$news_iteration]->post_title;
                echo $news_articles[$news_iteration]->post_excerpt;
          
              endif;
                
            endif;
    
    	endwhile; ?>
    
    	<?php if ( bp_activity_has_more_items() ) : ?>
    
    		<li class="load-more">
    			<a href="<?php bp_activity_load_more_link() ?>"><?php _e( 'Load More', 'buddypress' ); ?></a>
    		</li>
    
    	<?php endif; ?>
    
    	<?php if ( empty( $_POST['page'] ) ) : ?>
    
    		</ul>
    
    	<?php endif; ?>
    
    <?php else : ?>
    
    	<div id="message" class="info">
    		<p><?php _e( 'Sorry, there was no activity found. Please try a different filter.', 'buddypress' ); ?></p>
    	</div>
    
    <?php endif; ?>

    @tommyhares

    Participant

    Thanks Henry, I have been trying to use that. However, I need to iterate through blog posts, not display the same content repeated. Also, tried directly modifying the activity-loop in a child theme, but it only cycles until the next ajax query. Any other solutions?

    @tommyhares

    Participant
    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.

    @tommyhares

    Participant

    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.

    @tommyhares

    Participant

    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?

Viewing 9 replies - 1 through 9 (of 9 total)
Skip to toolbar