/    Sign up×
Community /Pin to ProfileBookmark

ohter pages get index.php style

Hello,

I’m making a website and my homepage (index.php) has a diffent layout then the rest of my pages.

I’m working with cases and when case (?p=2) = 2 you go to the about page. That page shoud have a different layout because I’m giving my div’s other styles but that page is still getting the css div style from the index.php.

I there a way to avoid this? It is really annoying and I cant find an easy answer.

If somebody could help me that would be great

Thankyou!

[code=php] <div id=”main-home-right”>

<?php
if(isset($_GET[‘p’]))
{
switch($_GET[‘p’])
{
case “1”:
default:
include “modules/content.php”;
break;
case “2”:
include “modules/about.php”;
break;
}
}
else
{
include “modules/content.php”;
}
?>
</div>[/code]

to post a comment
PHP

9 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJun 22.2012 — You could apply the same logic within the <head> section of the page to specify which CSS file gets used, perhaps?
Copy linkTweet thisAlerts:
@JoepioooauthorJun 22.2012 — Yes but I'm working with cases so every page after index gets also the style from index.php...

?p=2

?p=3 they all get the style from index.php to...

edit:

That could work but when I view my source code the about page (?p=2) also shows the div's I'm using on my index.php
Copy linkTweet thisAlerts:
@chrisranjanaJun 22.2012 — I there a way to avoid this? It is really annoying and I cant find an easy answer[/QUOTE]

If you can let us know what you are trying to AVOID exactly maybe I can help
Copy linkTweet thisAlerts:
@bsmbahamasJun 22.2012 — you don't need cases, just use an if in the head section:

[CODE]
<head>
<?php
if( isset( $_GET['p'] ) ){
$cssfile = 'css/' . $_GET['p'] . '.css';
if( file_exists($file) ){
include $file;
}
}
?>
</head>
[/CODE]


and just create a folder named 'css' on your server and name the css files 1.css, 3.css, 17.css, etc. you can use a <style> tag to include the default styles above this code, and then in the file 3.css it would overwrite the default style as long as the default style rules are not more specific. in any event you should be including .css files not .php files to handle styling
Copy linkTweet thisAlerts:
@cbVisionJun 22.2012 — name the css files 1.css, 3.css, 17.css, etc. [/QUOTE]

I'm not sure if this is a good recommendation. You're essential loading a new style sheet for each page you visit instead of simply loading 1 sheet to be used across the board. From a speed/resources point of view, this isn't a good solution.
Copy linkTweet thisAlerts:
@bsmbahamasJun 22.2012 — I'm not sure if this is a good recommendation. You're essential loading a new style sheet for each page you visit instead of simply loading 1 sheet to be used across the board. From a speed/resources point of view, this isn't a good solution.[/QUOTE]

i agree with this line of thinking, i offered it since he was already using includes. personally i'd just use unique classes and ids if it really had to be so conditional, or maybe even have php generate the style within the elements or the style tag in the header.

assuming he only has a few pages, then including css files conditionally won't be too bad, but i'd still opt for using one external stylesheet for default styling and possibly a second on some pages as needed hardcoded into the page as linked stylesheets or conditionally included via php

he needs to explain what he's trying to do more clearly, in most cases styling is just a case of being more specific with your css rules to determine what gets applied, or just adding more classes/ids as needed
Copy linkTweet thisAlerts:
@JoepioooauthorJun 24.2012 — Sorry for the bad explenation but my english is not that good.

I will try to explain it again. I inlcude my pages with cases and the php code of my cases is in a div like this (<div id="main-home-right">)

When case is 2 (about.php) that page gets the div style of main-home-right... That is very logical but I want that div on a whole other position on my about page. How can I realize that?
Copy linkTweet thisAlerts:
@bsmbahamasJun 25.2012 — from your original code it seems that you are not using a blog like wordpress but seem to be building a custom site with pages that load templates based on the query string e.g. ?p=1 or ?p=2, etc.

from what i can tell you are only using php to conditionally load the .php module not the css.

the simple thing to do would be to just give the div's unique id's or classes, and then just style it from your default .css stylesheet.

i.e. <div id='content'> and <div id='about'>

then in your css...

#content { border: 1px solid red; }

#about { border: 1px solid green; }

but i'm really not sure what you are after from your explanation
Copy linkTweet thisAlerts:
@jedaisoulJun 25.2012 — If you want to style the index page differently, give the DIVs on that page different names from the rest if the pages. E.g.

<div id=container>

</div>

and

<div id=index_container>

</div>

Then your CSS file can include separate rules for the index page. E.g.

#container {

max-width: 770px;

min-width: 300px;

}

#index_container {

max-width: 800px;

min-width: 320px;

}

etc...
×

Success!

Help @Joepiooo spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...