Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-06-2012, 10:16 PM   PM User | #1
operapixie
Regular Coder

 
Join Date: Nov 2011
Posts: 129
Thanks: 11
Thanked 0 Times in 0 Posts
operapixie can only hope to improve
Question PHP if/then statement to call specific CSS?

Hi there,
I've got a WordPress site I'm building, and I've got things set up so that the PHP knows not to display the sidebar on a Page, but will display it on a Post. Unfortunately, the width of the main text area is universally set up in the CSS to be right for when there's a sidebar. Is there a way to create some sort of an if/then statement that calls an alternate piece of CSS for the Page without the sidebar so my content will stretch the full width in that case?

Thanks in advance.

Please note that I am no expert in PHP. I can move things around and hopefully not break stuff, but I couldn't write a call from scratch to save my life right now.

~Laura
operapixie is offline   Reply With Quote
Old 12-06-2012, 11:33 PM   PM User | #2
Redcoder
Regular Coder

 
Redcoder's Avatar
 
Join Date: May 2012
Location: /dev/couch
Posts: 309
Thanks: 2
Thanked 46 Times in 45 Posts
Redcoder has a little shameless behaviour in the past
Yeah. You can. Something like. Or use a Switch Statement.

A switch statement is probably better.

PHP Code:
<?php
//Yourfile.php

if()//condition
{
     
$yourcssfile 'css1.css';   
}
elseif() 
//2nd condition
{
     
$yourcssfile 'css2.css'
}
?>

<html>
<head>
<link rel="stylesheet" type="text/css" href="<?=$yourcssfile?>">

</head>
</html>
__________________
For professional Hosting and Web design.....


NetEssentials.co.uk
Redcoder is offline   Reply With Quote
Old 12-07-2012, 12:54 AM   PM User | #3
Custard7A
Regular Coder

 
Custard7A's Avatar
 
Join Date: Jul 2010
Location: Australia
Posts: 269
Thanks: 32
Thanked 32 Times in 32 Posts
Custard7A is an unknown quantity at this point
Building on what Redcoder said, the condition you use is likely related to what you've done with PHP to only display the sidebar on some pages. Also, since you probably have a lot of CSS that you don't want to change or copy into a new file just to make it fit there being no sidebar, you could leave the current CSS, and just add a new CSS file in that supersedes the few select things you want by means of the cascade. If the condition is met that is.

PHP Code:


<html>
<head>
<link rel="stylesheet" type="text/css" href="original.css">

<?php

  
if(no sidebar) {

  print 
'<link rel="stylesheet" type="text/css" href="overwriting.css">';

  } 
?>

</head>
</html>
Custard7A is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:46 AM.


Advertisement
Log in to turn off these ads.