3

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 the 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!

2 Answers 2

2

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";}
?>
Sign up to request clarification or add additional context in comments.

1 Comment

your welcome and welcome to SO. Don't forget to mark whatever answer that's right in your condition. Just click on check mark on the left side of the answer.
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.