Hello,
i would like posts to have different repeating backgrounds depending on what category they belong to.
All posts from every category appear on one page, with the most recent post appearing first. Each post uses the same div id, so I can't define the background property as anything in CSS - that's what should change depending on the category of the post.
So I did some research into using PHP and CSS to create variables - I got as far as using style.php instead of style.css and that worked fine.
I understand how to declare variables in PHP but something just doesn't work.
What I would like to happen:
Category backgrounds are uploaded to img folder eg art_bg.jpg
CSS background property of div in style.php is a variable:
background: url(img/<?= $category; ?>_bg.jpg);
Variable is declared in style.php (in the same place where the browser is instructed to interpret the code as CSS):
$category = (don't know!);
This is the stage where I am stuck! If the value isn't in quotes, the stylesheet breaks. Template Tags can't be used outside The Loop, but I need the Template Tag the_category to appear in the variable declaration for my idea to work - even if they did, I don't think they would be recognised in quotes!
Any ideas? Can my CSS/PHP plan be followed through? Would appreciate any help, this is doing my head in rather! :)
Thanks,
James :)