[resolved] TwentyTen - Alternating post colour (3 posts)

  1. axim30
    Posted 6 years ago #

    I used to have code underneath in the loop to get alternating colours for my posts, by styling 'post odd' and 'post even'.

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>  
    <div class="post <?php echo $odd_or_even; $odd_or_even = ('odd'==$odd_or_even) ? 'even' : 'odd'; ?>" >

    Now TwentyTen is using the post_class() function, so how can I do this?
    Generating a <div> around the post_class() is possible but not very elegant, can I easily add this to the post_class?

  2. Michael
    Forum Moderator
    Posted 6 years ago #

    have you read the docu about post_class() ?


     $odd_or_even = ('odd'==$odd_or_even) ? 'even' : 'odd';
  3. axim30
    Posted 6 years ago #

    thanks alchymyth, read the doc and looked at the special cases.

    It didn't occur to me that it was this easy by passing the function result. I'm just using php for a month or so and trying to find my way around.

Topic Closed

This topic has been closed to new replies.

About this Topic