PHP Variables & CSS
-
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 thebackgroundproperty 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.phpinstead ofstyle.cssand 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
imgfolder egart_bg.jpgCSS
backgroundproperty of div instyle.phpis 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_categoryto 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 🙂
The topic ‘PHP Variables & CSS’ is closed to new replies.