Trying to wrap my brain around this.
Hi,
I have been trying to figure out how to keep adding themes to this:
<?
// This is the first theme
if($theme == 'theme1')
{
$stylesheet = "theme1.css";
$headerimg = "<div id="logo">Image for theme one goes here</div>";
}
// This is the second theme
else if($theme == 'theme2')
{
$stylesheet = "theme2.css";
$headerimg = "<div id="logo">Image for theme 2 goes here</div>";
}
// This is the third theme -- also the default theme
else
{
$theme = 'theme3';
$stylesheet = "theme3.css";
$headerimg = "<div id="logo"><img src="theme3.gif" alt="logo" /></div>";
}
?>
I'm working on making themes for my blog that uses a certain tutorial. Unfortunately they never finished or took out the links to the information for adding more themes.
Help would be wonderful, thank you in advance!
Sara
~*Sara*~
Mark Hensler posted this at 16:11 — 11th October 2002.
He has: 4,048 posts
Joined: Aug 2000
I think this may be easier..
<?php
switch ($theme) {
case 'theme1':
$stylesheet = \"theme1.css\";
$headerimg = \"<div id=\"logo\">Image for theme one goes here</div>\";
break;
case 'theme2':
$stylesheet = \"theme2.css\";
$headerimg = \"<div id=\"logo\">Image for theme 2 goes here</div>\";
break;
case 'theme3':
$stylesheet = \"theme3.css\";
$headerimg = \"<div id=\"logo\"><img src=\"theme3.gif\" alt=\"logo\" /></div>\";
break;
default:
$stylesheet = \"theme3.css\";
$headerimg = \"<div id=\"logo\"><img src=\"theme3.gif\" alt=\"logo\" /></div>\";
break;
}
?>
<?php
case 'blueberry':
$stylesheet = \"blueberry.css\";
$headerimg = \"<div id=\"logo\"><img src=\"blueberry.gif\" alt=\"logo\" /></div>\";
break;
?>
Mark Hensler
If there is no answer on Google, then there is no question.
DC_Sara posted this at 16:16 — 11th October 2002.
She has: 392 posts
Joined: Jan 2002
Thanks Mark, I will try this!
Sara
DC_Sara posted this at 16:28 — 11th October 2002.
She has: 392 posts
Joined: Jan 2002
I just tested it and it's wonderful. THANK YOU MARK! I have been pounding my head on the wall for a while with this hurdle. Now, I have learned something as well.
You can see the test blog here: http://www.blogland.com/b2/
Sara
~*Sara*~
zollet posted this at 22:45 — 11th October 2002.
He has: 1,016 posts
Joined: May 2002
Just to make it a little easier so that you don't have to add more code for every single theme...
<?php
//set the default theme
if(!isset($theme)) {
$theme = \"theme3\";
}
//whatever $theme is, that CSS and logo are loaded.
$stylesheet = $theme . \".css\";
$headerimg = \"<div id=\\"logo\\"><img src=\\"\" . $theme . \".gif\\" alt=\\"logo\\" /></div>\";
?>
Mark Hensler posted this at 22:46 — 11th October 2002.
He has: 4,048 posts
Joined: Aug 2000
and then I add "?theme=not_a_them" to the URL...
zollet posted this at 22:53 — 11th October 2002.
He has: 1,016 posts
Joined: May 2002
Well, if a user wants to edit the URL just to mess with it then they know what they're doing, right? But you could add a little check that will make sure the format is "theme#" where # is a number. Again, this code is just to make it easier so you can add themes without having to edit the code every time but if it's very important that the users can't edit the URL to a theme that doesn't exist then switch() is the way to go.
<?php
//set the default theme
if(!preg_match(\"/^theme\\d+$/\", $theme)) {
$theme = \"theme3\";
}
?>
And Mark, I'm not trying to say your code is bad or anything like that at all, in fact it is very good but I thought for a user that doesn't know much about programming and how to edit/add to it, this way might be better (easier)...
Mark Hensler posted this at 05:49 — 12th October 2002.
He has: 4,048 posts
Joined: Aug 2000
Your probably right. I was just, eh... testing you.
DC_Sara posted this at 12:18 — 12th October 2002.
She has: 392 posts
Joined: Jan 2002
Thanks for that Zollet although simplier to you, it's more confusing to me. I guess I have to stare at things a while! I will look at it this afternoon and break it apart.
I tried to take out the escapes on the above code, that I did use, and received a parse error, I used single quotes as well. Any clues as to why that happened?
Also, this is in my index.php to call in the themes.php
<!-- The theme links --><h2>Skin me</h2><br />
<A href="<?= $_SERVER['PHP_SELF']; ?>?theme=theme1">Fall</a><br />
<A href="<?= $_SERVER['PHP_SELF']; ?>?theme=theme2">America</a><br />
<A href="<?= $_SERVER['PHP_SELF']; ?>?theme=theme3">Butterflies*</a><br />
<A href="<?= $_SERVER['PHP_SELF']; ?>?theme=theme4">Halloween</a><br /><br />
Is there a way to make it where I can put the themes in separate folders. The above code makes it impossible and I don't know how to edit it to make it work. I have everything in the blog directory and I hate that as it's hard to keep track of everything.
Thanks for y'all's help.
Sara
~*Sara*~
zollet posted this at 20:37 — 12th October 2002.
He has: 1,016 posts
Joined: May 2002
You could make a directory for each of your themes.. and then instead of loading theme1.css, theme2.css, you could load ./theme1/style.css, ./theme2/style.css, etc...
Simple change...
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.