New Landing How can we help? Themeforest Theme Support Dante How to add a class to every other post

Viewing 4 posts - 1 through 4 (of 4 total)
  • Posted in: Dante
  • #37563
    Kyle – SUPPORT
    Moderator
    Post count: 35880

    Hi Ed

    I want to add a different class to every other blog post, for e.g. the 2nd, 4th, 6th etc.

    I found this online: http://wordpress.org/support/topic/style-odd-and-even-posts
    but with dante it’s not as easy as that. The style will need to be on the < li >’s

    Is this easy enough to do or not?

    Thanks

    Kyle

    #37572
    Kyle – SUPPORT
    Moderator
    Post count: 35880

    SOLVED

    Anybody else who wants to do this just simply add this to your function.php file:

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

    #38037
    Swift Ideas – Ed
    Keymaster
    Post count: 15264

    Thanks for posting that kyle!

    My solution would have been with CSS using :nth-child, but this works too!

    – Ed

    #38040
    Melanie – SUPPORT
    Member
    Post count: 11032

    Fantastic! Thanks for letting us know

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in and have valid license to reply to this topic.

License required for the following item
Login and Registration Log in · Register