• Resolved alam7o

    (@alam7o)


    Hi all
    how to create different styles for posts in index.php ?

    example:

    <div class="backred">post 1</div>
    <div class="backblue">post 2</div>
    <div class="backred">post 3</div>
    <div class="backblue">post 4</div>
    <div class="backred">post 5</div>
    <div class="backblue">post 6</div>

    i use this code

    <?php
    if(have_posts()): while(have_posts()): the_post();
    if($post->ID%2==0){ ?>
    <div class="backred">post 1</div>
    <?php
    } else { ?>
    <div class="backblue">post 2</div>
    <?php }
    endwhile; endif; ?>

    but In this case show
    http://www.upsara.com/images/n3wn_1231.jpg

    please help me

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi

    Could you please try the following code.

    <?php
    $i=1;
    if(have_posts()): while(have_posts()): the_post();
    if($i%2==0){ ?>
    <div class="backred">post 1</div>
    <?php
    } else { ?>
    <div class="backblue">post 2</div>
    <?php }
    $i++;
    endwhile; endif; ?>

    I hope this will be helpful to you.

    Thread Starter alam7o

    (@alam7o)

    thanks for your answer
    i fixed with this style

    .posts:nth-last-of-type(odd) {background: green;}
    .posts:nth-last-of-type(even) {background: yellowgreen;}

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

The topic ‘different styles for posts’ is closed to new replies.