I'm trying to alternate the background on a theme page that is displaying a custom loop:

$args = array( 'post-type' => 'portfolio', 'posts_per_page' => 10 );
                        $loop = new WP_Query( $args );
                        $count = 0;
                        while ($loop->have_posts() ) : $loop->the_post();

<div class="wrapper <?php if(++$count%2==0) echo 'grey-box'; else echo 'white-box'; ?>">

<div class="portfolio-picture <?php if(++$count%2==0) echo 'portfolio-grey-box'; else echo 'portfolio-white-box'; ?>">

                        <?php $videocode = get_post_meta($post->ID, 'video-embed-code', true); //is the custom field being used?

                        if ($videos) {

                            echo $videocode;



                        if ( has_post_thumbnail() ) {




                    <div class="portfolio-description">

                        <p><strong><?php the_title(); ?></strong></p>

                        <p><?php the_content(); ?></p>


                <div class="clear"></div>

                <?php endwhile; ?>

But the styles don't seem to change. Am I missing something?

1 Answer 1


You're incrementing $count twice in every iteration of the loop, the first if will always be false and the second will always be true.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.