WordPress.org

Ready to get started?Download WordPress

Forums

Alternate Post BG color (3 posts)

  1. astereo
    Member
    Posted 6 years ago #

    I know this has been done before and, with just a few lines of php I'm sure, can easily be accomplished again. Most of the places I could find this talked about were fairly outdated, so I was hoping someone would have a working, updated solution.

    Here's an example loop I have:

    <?php $my_query = new WP_Query('category_name=sale&showposts=20');
    
      while ($my_query->have_posts()) : $my_query->the_post();
    
      $do_not_duplicate = $post->ID; ?>
        <div class="entry">
          <h2><a href="<?php the_permalink(); ?>">
            <?php the_title(); ?>
            </a>
            <?php foreach((get_the_category()) as $cat)
     { echo '<img src="urlremoved.com/images/' . $cat->cat_ID . '.gif"
    alt="' . $cat->cat_name . '" />'; } ?>
          </h2>
          <div class="date"><img src="<?php bloginfo('template_directory'); ?>/images/clock.gif" alt="Date" />
            <?php the_time('n/j/y g:i A') ?> <img src="<?php bloginfo('template_directory'); ?>/images/user.gif" alt="Seller" /> <?php the_author_posts_link(); ?> <img src="<?php bloginfo('template_directory'); ?>/images/views.gif" alt="Views" /> <?php if(function_exists('the_views')) { the_views(); } ?>
          </div>
    </div>
        <?php endwhile; ?>

    All I want to do is drop some php in there that will alternate the Background color of the class entry, for example, entry1 and entry2 with just different background colors.

    Any help ASAP would be great!
    TIA!

  2. astereo
    Member
    Posted 6 years ago #

    Anyone ?

  3. WPChina
    Member
    Posted 6 years ago #

    Did you find a fix for this? I want to do the same thing for posts on my blog. I can do it for comments, but that seems not to work for posts. Check this thread for info on the CSS for comments.

Topic Closed

This topic has been closed to new replies.

About this Topic