Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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;

                        }

                        else

                        if ( has_post_thumbnail() ) {
                            the_post_thumbnail('portfolio-picture');

                        };

                        ?>

                    </div>



                    <div class="portfolio-description">

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


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


                </div>

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

            </div>
                <?php endwhile; ?>

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

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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