Title: Using Plugin with Alternating Post Classes
Last modified: July 15, 2019

---

# Using Plugin with Alternating Post Classes

 *  Resolved [marisax](https://wordpress.org/support/users/marisax/)
 * (@marisax)
 * [6 years, 9 months ago](https://wordpress.org/support/topic/using-plugin-with-alternating-post-classes/)
 * I’m using the code below in my theme to change the background color for alternating
   posts and it’s working for the posts that are already shown, however it’s not
   working in conjunction with the Load More plugin. Any suggestions?
 * <?php
    // Add ‘odd’ and ‘even’ post classes function alternating_post_class (
   $classes ) { global $current_class; if( is_home() ): $classes[] = $current_class;
   $current_class = ($current_class == ‘odd’) ? ‘even’ : ‘odd’; endif; return $classes;}
   add_filter (‘post_class’, ‘alternating_post_class’); global $current_class; $
   current_class = ‘odd’; ?>

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

 *  Plugin Author [Darren Cooney](https://wordpress.org/support/users/dcooney/)
 * (@dcooney)
 * [6 years, 9 months ago](https://wordpress.org/support/topic/using-plugin-with-alternating-post-classes/#post-11736996)
 * Hi [@marisax](https://wordpress.org/support/users/marisax/)
    Are you using the`
   post_class` function in your Repeater Template?
 *  Thread Starter [marisax](https://wordpress.org/support/users/marisax/)
 * (@marisax)
 * [6 years, 9 months ago](https://wordpress.org/support/topic/using-plugin-with-alternating-post-classes/#post-11737074)
 * This is the repeater template – the second div is the one that should have alternating
   colors:
 * <div class=”<?php mesmerize_print_archive_entry_class(); ?>” data-masonry-width
   =”<?php mesmerize_print_masonry_col_class(true); ?>”>
    <div id=”post-<?php the_ID();?
   >” <?php post_class(‘blog-post card ‘); ?>> <div class=”post-content”>
 *  <?php mesmerize_print_post_thumb(); ?>
 *  <div class=”col-xs-12 col-padding col-padding-xs”>
    <h3 class=”post-title”> ”
   rel=”bookmark”> <?php the_title(); ?>  </h3> <?php get_template_part(‘template-
   parts/content-list-post-meta’); ?>
 *  <div class=”post-excerpt”>
    <?php the_excerpt(); ?> </div> </div>
 *  </div>
    </div> </div>
 *  Plugin Author [Darren Cooney](https://wordpress.org/support/users/dcooney/)
 * (@dcooney)
 * [6 years, 9 months ago](https://wordpress.org/support/topic/using-plugin-with-alternating-post-classes/#post-11740602)
 * Seems like that function is not being run.
    In your Repeater Template you could
   do this.
 *     ```
       <?php $class = ($alm_item % 2 !== 0) ? ' odd' : ' even'; ?>
       <div class="<?php mesmerize_print_archive_entry_class(); ?><?php echo $class; ?>" data-masonry-width="<?php mesmerize_print_masonry_col_class(true); ?>">
          <div id="post-<?php the_ID(); ?>" <?php post_class('blog-post card '); ?>>
             <div class="post-content">      
   
                ...
   
             </div>
          </div>
       </div>
       ```
   
 * Using [ALM Variables](https://connekthq.com/plugins/ajax-load-more/docs/variables/)
   to get the odd/even class.
 *  Thread Starter [marisax](https://wordpress.org/support/users/marisax/)
 * (@marisax)
 * [6 years, 9 months ago](https://wordpress.org/support/topic/using-plugin-with-alternating-post-classes/#post-11740843)
 * Thanks for your reply! This didn’t seem to work either. I’m not super familiar
   with PHP so trying to decipher how else to rework this. Any other ideas? Appreciate
   your help!
 *  Plugin Author [Darren Cooney](https://wordpress.org/support/users/dcooney/)
 * (@dcooney)
 * [6 years, 9 months ago](https://wordpress.org/support/topic/using-plugin-with-alternating-post-classes/#post-11740849)
 * Can you share a link with the solution I proposed in action?
 *  Thread Starter [marisax](https://wordpress.org/support/users/marisax/)
 * (@marisax)
 * [6 years, 9 months ago](https://wordpress.org/support/topic/using-plugin-with-alternating-post-classes/#post-11740990)
 * Sure, you can scroll down and see the load more posts button: [https://www.temporary-url.com/74C2](https://www.temporary-url.com/74C2)
 *  Plugin Author [Darren Cooney](https://wordpress.org/support/users/dcooney/)
 * (@dcooney)
 * [6 years, 9 months ago](https://wordpress.org/support/topic/using-plugin-with-alternating-post-classes/#post-11740999)
 * Ok, the issue is the classes are on the wrong divs.
 *     ```
       <?php $class = ($alm_item % 2 !== 0) ? ' odd' : ' even'; ?>
       <div class="<?php mesmerize_print_archive_entry_class(); ?>" data-masonry-width="<?php mesmerize_print_masonry_col_class(true); ?>">
          <div id="post-<?php the_ID(); ?>" <?php post_class('blog-post card '.$class); ?>>
             <div class="post-content">      
   
                ...
   
             </div>
          </div>
       </div>
       ```
   
 *  Thread Starter [marisax](https://wordpress.org/support/users/marisax/)
 * (@marisax)
 * [6 years, 9 months ago](https://wordpress.org/support/topic/using-plugin-with-alternating-post-classes/#post-11741039)
 * Ah! Fantastic! Thanks so much for your help!
 *  Thread Starter [marisax](https://wordpress.org/support/users/marisax/)
 * (@marisax)
 * [6 years, 9 months ago](https://wordpress.org/support/topic/using-plugin-with-alternating-post-classes/#post-11741098)
 * I also just noticed the “Read more” link after the excerpts are missing – any
   ideas on that? (I can also start a new thread if it’s not a quick fix)
 *  Thread Starter [marisax](https://wordpress.org/support/users/marisax/)
 * (@marisax)
 * [6 years, 9 months ago](https://wordpress.org/support/topic/using-plugin-with-alternating-post-classes/#post-11741775)
 * Nvm solved!

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

The topic ‘Using Plugin with Alternating Post Classes’ is closed to new replies.

 * ![](https://ps.w.org/ajax-load-more/assets/icon-256x256.png?rev=2944639)
 * [Ajax Load More – Infinite Scroll, Load More, & Lazy Load](https://wordpress.org/plugins/ajax-load-more/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/ajax-load-more/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/ajax-load-more/)
 * [Active Topics](https://wordpress.org/support/plugin/ajax-load-more/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/ajax-load-more/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/ajax-load-more/reviews/)

 * 10 replies
 * 2 participants
 * Last reply from: [marisax](https://wordpress.org/support/users/marisax/)
 * Last activity: [6 years, 9 months ago](https://wordpress.org/support/topic/using-plugin-with-alternating-post-classes/#post-11741775)
 * Status: resolved