• Resolved marisax

    (@marisax)


    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

    (@dcooney)

    Hi @marisax
    Are you using the post_class function in your Repeater Template?

    Thread Starter marisax

    (@marisax)

    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

    (@dcooney)

    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 to get the odd/even class.

    Thread Starter marisax

    (@marisax)

    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

    (@dcooney)

    Can you share a link with the solution I proposed in action?

    Thread Starter marisax

    (@marisax)

    Sure, you can scroll down and see the load more posts button: https://www.temporary-url.com/74C2

    Plugin Author Darren Cooney

    (@dcooney)

    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

    (@marisax)

    Ah! Fantastic! Thanks so much for your help!

    Thread Starter marisax

    (@marisax)

    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

    (@marisax)

    Nvm solved!

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Using Plugin with Alternating Post Classes’ is closed to new replies.