Load css based on word in url
I'd like to be able to load a separate css file depending on words in the page url. It's for a cms that has a single index.php and all th开发者_开发知识库e url's for the pages are created dynamically.
What I would like to happen is if the url contains certain words, then a specific css file must load, if the url doesn't contain the words then another css file must load.
I've managed to get it working with one word, however I can't figure out how to get it to check for more words.
The code:
<?php if (stripos($_SERVER['REQUEST_URI'],'/administration/') !== false){$style = "css/style.css";} else {$style = "css/style1.css";}?>
I'll appreciate any help! Thank you!
I'm not really sure what you mean. This is my best guess. You need more that 2 condition:
<?php
if (stripos($_SERVER['REQUEST_URI'],'/administration/') !== false){$style = "css/style.css";}
else if(stripos($_SERVER['REQUEST_URI'],'/member/') !== false) {$style = "css/style2.css";}
else if(stripos($_SERVER['REQUEST_URI'],'/customer/') !== false) {$style = "css/style3.css";}
else {$style = "css/style1.css";}
?>
Well, you could write a more sophisticated switch
or elseif
, but I'd figure it will work fine if you just copy this line of code and modify the trigger word and the css file name.
精彩评论