10 Replies to “Alternating Posts Backgrounds for Twenty Ten”

i applied the above code..but i didnt get the result..i am using stylo theme..what is the process for alternate background colors for posts of stylo theme in word press..can any one please help me in this issue..what are the pages i need to edit..

Hey!
I love how simple this is. The only problem is all my posts have a class of dark, instead of alternating between bright and dark. I don’t understand how the code in the “switcher” alternates the classes. Could you please explain it, in case there is something I need to adjust?

I’m trying to alternate my posts so that I have the first one floating left, then the next one floating right, etc. so they alternate. I figure all I need to do is assign them right or left classes, then style them accordingly. Am I misunderstanding something?

this line:<?php $stripe = ($stripe == 'dark') ? 'bright' : 'dark'; ?>
is a shortform for:<?php if($stripe == 'dark') { $stripe = 'bright'; }
else { $stripe = 'dark'; } ?>
if the code is encountered the first time, $stripe is not set, i.e. is empty, and not ‘dark’; therefore the if statement sets $stripe = 'dark'; the second time, $stripe is ‘dark’, therefore the if statement sets $stripe = 'bright', etc. (use ‘left’ and ‘right’ instead for your plans).
if you have wordpress related questions, consider to join the wordpress.org support forum and inquire there.

I’m trying to do this in a twentyeleven child theme, but I’m beginning to think it’s not possible. The Loop seems to be split between the index.php and the content.php, and a lot of the post formats have their own if statements. I really only want to alternate the standard format, since that is the one with the thumbnail.

I’ve been combing through the WP forum, and noticed that you have answered quite a few people with variations of this and the odd/even version. I’ve tried about 30 different variations and nothing works. Do you think it’s possible to do this (in the twentyeleven theme) or should I give up?

(I first tried it with left and right, like you suggest in your reply, but it didn’t work, so I thought I should copy yours verbatim, and just style it left and right but that didn’t work either.)