• Resolved maggieymae

    (@maggieymae)


    I’ve been trying to adjust css to show odd or even posts with different background colors. So far I can’t figure it out. Does anyone know if it can be done?
    Thank you in advance.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi, will you please share your site URL so that I can tell you exactly how to do it?

    Add this code in the function.php file.

    function alternatepost_post_class ( $classes ) {
       global $current_class;
       $classes[] = $current_class;
       $current_class = ($current_class == 'odd') ? 'even' : 'odd';
       return $classes;
    }
    add_filter ( 'post_class' , 'alternatepost_post_class' );
    global $current_class;
    $current_class = 'odd';

    Now add color using the CSS –

    .even {
    background:#a600f9;
    }
    .odd {
    background:#25ddc2;
    }

    Hope it will help you to resolve your query.

    Thread Starter maggieymae

    (@maggieymae)

    Figured it out. Sharing.
    .grid-entry:nth-child(odd)

    Thread Starter maggieymae

    (@maggieymae)

    Thanks for getting back to me. I didn’t see your replies before I posted again. You went to so much trouble. It is greatly appreciated. The css snippet I posted seems to work. The site I’m working on isn’t open yet.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘post grid alternating backgrounds?’ is closed to new replies.