Switching Themes with PHP |
![]() ![]() |
Switching Themes with PHP |
![]()
Post
#1
|
|
![]() ^ Mrs. Jonas ![]() ![]() ![]() ![]() ![]() Group: Member Posts: 592 Joined: Apr 2005 Member No: 263,313 ![]() |
The closest I got when searching was this, and it didn't help.
I'm working on another website, and want to be able to switch themes, and like Heather had said, switch it on all pages. It's NOT wordpress, by the way. I have header.inc and footer.inc, and then index.php which includes both. I know that I can make header2.inc and footer2.inc, but I don't know how to make some sort of dropdown where you can choose whether you want theme 1 or theme 2, and how to make it include the appropriate header and footer. I tried googling it, but only came up with Wordpress and B2 hacks, which isn't helping me at all. |
|
|
*mipadi* |
![]()
Post
#2
|
Guest ![]() |
Are you doing it for a general website? It's fairly simple, assuming I am following you correctly. It involves three things: making a separate stylesheet for each "theme", making a form to select themes, and write code to handle that.
First, the form: Just make a normal HTML form. The code will look something like this: CODE <form method="get" action="<?php echo $_SERVER['SCRIPT_NAME']; ?> <select name="style"> <option value="stylea">A</option> <option value="styleb">B</option> </select> <input type="submit" value="Submit"/> </form>[/code Put this wherever you want the form to appear. Naturally, you fill in an <option> tag for each option. Feel free to customize the look of the form, as well as the label for the Submit button (in the "value" attribute"). Now, I'm assuming your header.inc file includes the stylesheet, with a line such as: [code]<link rel="stylesheet" type="text/css" href="style.css"/> (<?php echo $_SERVER['SCRIPT_NAME']; ?> inserts the filename of the page.) What you need to do is grab the value from the form, and insert it into HTML code. Assume for a second your stylesheets are named according to the values you used in your form (i.e., you have a style called "stylea.css" and a style called "styleb.css"). When you select a new style, your page will change from, say, page.php to page.php?style=stylea. "style", of course, contains the value of the stylesheet you selected. Your coding in your header file would look something like this: CODE <html> <head> <title>blah blah</title> <?php echo '<link rel="stylesheet" type="text/css" href="'.$_GET['style'].'"/>'; ?> <!-- rest of code here --> <?php echo '<link rel="stylesheet" type="text/css" href="'.$_GET['style'].'"/>'; ?> inserts the appropriate <link> tag, plus the value of the "style" property in the query string (the thing after the ? in the URL, in this case, ?style=styla). Now, whenever the user selects a new theme, the appropriate stylesheet will be included. (Also, as a minor side note, it is more secure to name include files as "include.php" rather than "include.inc". If a user navigates directly to the file (such as by typing in host.com/include.inc, they will see all the source code for the file--which is had if the source code contains passwords to databases or other confidential data. However, if a user navigates to an include file at host.com/include.php, the include file will be executed and the user will only see output that is explicity shown using PHP.) |
|
|
![]()
Post
#3
|
|
![]() ^ Mrs. Jonas ![]() ![]() ![]() ![]() ![]() Group: Member Posts: 592 Joined: Apr 2005 Member No: 263,313 ![]() |
I think that's what I'm looking for. Let me try it out later this evening and I'll tell you if that works (so don't close this yet, ever-helpful mods). But I do think that should work.
Also, thanks for telling me about the .inc files. The tutorial I used for converting to PHP just said to use that, so thanks for telling me about the security risks! |
|
|
![]()
Post
#4
|
|
![]() ^ Mrs. Jonas ![]() ![]() ![]() ![]() ![]() Group: Member Posts: 592 Joined: Apr 2005 Member No: 263,313 ![]() |
-sorry, double post-
|
|
|
![]()
Post
#5
|
|
![]() i lost weight with Mulder! ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Official Designer Posts: 4,070 Joined: Jan 2005 Member No: 79,019 ![]() |
are you looking for this: http://codegrrl.com/tutorials/php/skinning_your_site.php ?
im going to try this soon. after finals. |
|
|
![]()
Post
#6
|
|
![]() creepy heather ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Official Member Posts: 4,208 Joined: Aug 2004 Member No: 41,580 ![]() |
oh, mel, i bookmarked the site i got my code from!
http://textpattern.org/tips/328/style-switcher-non-plugin |
|
|
![]()
Post
#7
|
|
![]() i lost weight with Mulder! ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Official Designer Posts: 4,070 Joined: Jan 2005 Member No: 79,019 ![]() |
QUOTE(Heathasm @ Dec 6 2005, 4:12 AM) oh, mel, i bookmarked the site i got my code from! http://textpattern.org/tips/328/style-switcher-non-plugin i love you heather! ![]() i am so doing this after finals! |
|
|
![]()
Post
#8
|
|
t-t-t-toyaaa ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Official Member Posts: 19,821 Joined: Apr 2004 Member No: 11,270 ![]() |
Just be aware that (well according to what people told me) it takes up alot of space sometimes. Im not exactly sure though. I wanted too but I think it might like take up all the space..
does it? |
|
|
![]()
Post
#9
|
|
![]() creepy heather ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Official Member Posts: 4,208 Joined: Aug 2004 Member No: 41,580 ![]() |
no, not at all
its just a few lines of php and extra stylesheets |
|
|
![]()
Post
#10
|
|
![]() i lost weight with Mulder! ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Official Designer Posts: 4,070 Joined: Jan 2005 Member No: 79,019 ![]() |
i dont want to steal lisa's bandwidth..
i might try it... but im worried about taking all of lisa's space.. |
|
|
![]()
Post
#11
|
|
t-t-t-toyaaa ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Official Member Posts: 19,821 Joined: Apr 2004 Member No: 11,270 ![]() |
^ you should ask who knows her bandwith might not even be affected. I haven't talked to her in MONTHS! we used to talk everyday =/ but I don't think it will mess with her bandwith
|
|
|
![]()
Post
#12
|
|
![]() ^ Mrs. Jonas ![]() ![]() ![]() ![]() ![]() Group: Member Posts: 592 Joined: Apr 2005 Member No: 263,313 ![]() |
QUOTE(insomniac @ Dec 5 2005, 9:08 PM) are you looking for this: http://codegrrl.com/tutorials/php/skinning_your_site.php ? im going to try this soon. after finals. Ooh, I like that a little better... well, I'll try this one and then Michael's and then maybe Heather's and whichever one works... DOES it affect space and bandwidth and such? I wouldn't think so... ![]() |
|
|
*mipadi* |
![]()
Post
#13
|
Guest ![]() |
|
|
|
![]()
Post
#14
|
|
![]() i lost weight with Mulder! ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Official Designer Posts: 4,070 Joined: Jan 2005 Member No: 79,019 ![]() |
how would you do this with wordpress?
.... im not really sure how, since all my css is part of my wp theme. its probably really simple knowing me. |
|
|
![]()
Post
#15
|
|
![]() ^ Mrs. Jonas ![]() ![]() ![]() ![]() ![]() Group: Member Posts: 592 Joined: Apr 2005 Member No: 263,313 ![]() |
http://codegrrl.com/tutorials/php/skinning_your_site.php
SUCCESS!!! Anyhow, I think if all of your CSS is in your wordpress, you could just download a theme switcher plugin, right? And just have different wordpress themes that you have edited. And if your other pages include the same header.php and footer.php files, it should all change. I think. SUCESS YAYYYYY..... |
|
|
![]()
Post
#16
|
|
![]() i lost weight with Mulder! ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Official Designer Posts: 4,070 Joined: Jan 2005 Member No: 79,019 ![]() |
^you use wordpress right?
how are you doing it? |
|
|
![]()
Post
#17
|
|
![]() ^ Mrs. Jonas ![]() ![]() ![]() ![]() ![]() Group: Member Posts: 592 Joined: Apr 2005 Member No: 263,313 ![]() |
Well, I haven't adapted it to work with wordpress yet. The site I'm working on is just a site... but if and when I get it figured out, you'll be the first to know. *writes post-it note* But my guess is that you just create multiple wordpress themes and then just download the plugin (I think there's a link to it in the first post of this thread) to switch between themes. I'm not sure... it might get hairy when you start using other pages.
Anyhow. PROBLEM. So I followed that tutorial completely, and... well, it works, for the most part. It switches the theme, but when you go back to browsing the original site, it goes back to the original theme. Here's the site: http://writersblock.melilyn.com/index.php [it's still under a lot of construction, and the themes are just example themes, but if you click on 'theme switcher' you'll see what I mean.] HELP? ![]() |
|
|
*mipadi* |
![]()
Post
#18
|
Guest ![]() |
QUOTE(Fabio. @ Dec 6 2005, 10:48 PM) Here's the site: http://writersblock.melilyn.com/index.php [it's still under a lot of construction, and the themes are just example themes, but if you click on 'theme switcher' you'll see what I mean.] HELP? ![]() The theme information is passed along in the query string--the part of the URL that says ?newskin=2 or whatever. However, the main page link links back to index.php, and loses the value in the query string. You have to keep passing the value along; you can do that by making sure all your links end in something like this: CODE <a href="page.php?newskin=<?php echo $_GET['newskin']; ?>">link text</a>
|
|
|
![]()
Post
#19
|
|
![]() i lost weight with Mulder! ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Official Designer Posts: 4,070 Joined: Jan 2005 Member No: 79,019 ![]() |
michael, do you know how to make it work with wordpress when you're not using wordpress for all of the pages?
|
|
|
*mipadi* |
![]()
Post
#20
|
Guest ![]() |
|
|
|
![]()
Post
#21
|
|
![]() ^ Mrs. Jonas ![]() ![]() ![]() ![]() ![]() Group: Member Posts: 592 Joined: Apr 2005 Member No: 263,313 ![]() |
QUOTE(mipadi @ Dec 6 2005, 10:54 PM) You have to keep passing the value along; you can do that by making sure all your links end in something like this: CODE <a href="page.php?newskin=<?php echo $_GET['newskin']; ?>">link text</a> Would I do this for each and every link on the entire site? Or just the link back to the index? Thank you for helping, by the way... Edit: Ahh, all of them. I tested it out and it seems to work. So my problem is resolved, it's just Michelle still! <3 Thanks, Michael. This post has been edited by Fabio.: Dec 6 2005, 11:28 PM |
|
|
![]()
Post
#22
|
|
![]() i lost weight with Mulder! ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Official Designer Posts: 4,070 Joined: Jan 2005 Member No: 79,019 ![]() |
QUOTE(Fabio. @ Dec 6 2005, 11:06 PM) Edit: Ahh, all of them. I tested it out and it seems to work. So my problem is resolved, it's just Michelle still! <3 ![]() its just that my wordpress theme is composed of many files... i guess i could make it just a css file... but i couldnt. id still have to have the blog file, the comments file.. should i just use the theme switcher? |
|
|
![]() ![]() |