Welcome to Geeklog, Anonymous Monday, November 25 2024 @ 03:17 am EST
Geeklog Forums
Changing the theme with the topic
Status: offline
Dirk
Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany
For a site I'm working on, I wanted the theme to change when you change the topic. Now, this has been discussed before and the Chameleon hack was developed as a result.
However, when all you need are a few color changes, there's a simpler solution that doesn't require any changes to Geeklog's core code.
This relies on the fact that you can use PHP in a theme's header.thtml file. To keep things readable, PHP code can also be added to the functions.php file that's part of every theme, so that you could add a function to that file and then simply call it from header.thtml.
So here's a simplified version of what I did:
In the theme's functions.php, add a function like this:
{
global $topic;
switch ($topic) {
case 'GeekLog':
$color = 'red';
break;
case 'General':
$color = 'green';
break;
default:
$color = 'black';
break;
}
$retval = '<style type="text/css">' . LB
. '.current-color {' . LB
. ' color: ' . $color . ';' . LB
. ' background-color: white;' . LB
. '}' . LB
. '</style>' . LB;
return $retval;
}
This function simply checks what the current topic is and then emits CSS for a class called 'current-color', setting the foreground color accordingly.
All you have to do now is to add a call to that function in your theme's header.thtml like this:
...
<?php theme_emitCSS (); ?>
</head>
and then use
This can be extended to emit CSS using background images and other, more complicated CSS rules. You can also check what the current PHP file is (using
Hope it helps someone ...
bye, Dirk
However, when all you need are a few color changes, there's a simpler solution that doesn't require any changes to Geeklog's core code.
This relies on the fact that you can use PHP in a theme's header.thtml file. To keep things readable, PHP code can also be added to the functions.php file that's part of every theme, so that you could add a function to that file and then simply call it from header.thtml.
So here's a simplified version of what I did:
In the theme's functions.php, add a function like this:
Text Formatted Code
function theme_emitCSS (){
global $topic;
switch ($topic) {
case 'GeekLog':
$color = 'red';
break;
case 'General':
$color = 'green';
break;
default:
$color = 'black';
break;
}
$retval = '<style type="text/css">' . LB
. '.current-color {' . LB
. ' color: ' . $color . ';' . LB
. ' background-color: white;' . LB
. '}' . LB
. '</style>' . LB;
return $retval;
}
All you have to do now is to add a call to that function in your theme's header.thtml like this:
Text Formatted Code
<head>...
<?php theme_emitCSS (); ?>
</head>
class="current-color"
wherever you need it, e.g. in the blockheader.thtml template file.This can be extended to emit CSS using background images and other, more complicated CSS rules. You can also check what the current PHP file is (using
$HTTP_SERVER_VARS['PHP_SELF']
, after adding $HTTP_SERVER_VARS
to the list of global variables for that function) to select colors for Geeklog's calendar, links section, etc.Hope it helps someone ...
bye, Dirk
27
14
Quote
Status: offline
orfilms
Forum User
Regular Poster
Registered: 08/02/05
Posts: 70
It doesn't seem to be working for me, i put the php call in the header, and in functions I'm putting:
{
global $topic;
switch ($topic) {
case 'DVD':
$color = 'slashdvd.jpg';
break;
default:
$color = 'logo/imagerotator.php';
break;
}
$retval = '<style type="text/css">' . LB
. '#header {' . LB
. 'width: 100%;' . LB
. 'height: 150px;' . LB
. 'white-space: nowrap;' . LB
. 'background-color: #897F75;' . LB
. 'text-align: left;' . LB
. 'background-image: url(images/$color);' . LB
. 'background-repeat: no-repeat;' . LB
. 'padding: 0px 0px 0px 0px;' . LB
. '}' . LB
. '</style>' . LB;
return $retval;
}
Shouldn't that work? Nothing comes up in the page source where i put the php call...
Text Formatted Code
function theme_emitCSS (){
global $topic;
switch ($topic) {
case 'DVD':
$color = 'slashdvd.jpg';
break;
default:
$color = 'logo/imagerotator.php';
break;
}
$retval = '<style type="text/css">' . LB
. '#header {' . LB
. 'width: 100%;' . LB
. 'height: 150px;' . LB
. 'white-space: nowrap;' . LB
. 'background-color: #897F75;' . LB
. 'text-align: left;' . LB
. 'background-image: url(images/$color);' . LB
. 'background-repeat: no-repeat;' . LB
. 'padding: 0px 0px 0px 0px;' . LB
. '}' . LB
. '</style>' . LB;
return $retval;
}
Shouldn't that work? Nothing comes up in the page source where i put the php call...
26
28
Quote
Status: offline
Dirk
Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany
That CSS snippet should be there, at least, if you do a "view source" (or whatever the option is called) in your browser, i.e. have a look at the actual HTML of the page.
What won't work is the use of $color, as you put it between single quotes there. PHP doesn't replace variables enclosed in single quotes, so you would end up with '$color' in your CSS.
bye, Dirk
What won't work is the use of $color, as you put it between single quotes there. PHP doesn't replace variables enclosed in single quotes, so you would end up with '$color' in your CSS.
bye, Dirk
21
19
Quote
Status: offline
orfilms
Forum User
Regular Poster
Registered: 08/02/05
Posts: 70
Well nothing is showing up in the source at all where i put the php call:
I'm assuming there must be something wrong with my call? Is there any way to put the php in the header.thtml to see if that works?
Text Formatted Code
<?php theme_emitCSS (); ?>I'm assuming there must be something wrong with my call? Is there any way to put the php in the header.thtml to see if that works?
24
23
Quote
Status: offline
Dirk
Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany
Whoops, the above example is missing a "print" statement:
...
<?php print theme_emitCSS (); ?>
</head>
Funny that nobody noticed (or bothered to mention) it in over a year ...
bye, Dirk
Text Formatted Code
<head>...
<?php print theme_emitCSS (); ?>
</head>
Funny that nobody noticed (or bothered to mention) it in over a year ...
bye, Dirk
17
24
Quote
Status: offline
orfilms
Forum User
Regular Poster
Registered: 08/02/05
Posts: 70
This worked great...
but than I think it caused a few errors (I'm pretty sure it was this mod)
When people try to log off or log on it doesn't let them and gives them a refresh page that says:
"Warning: Cannot modify header information - headers already sent by (output started at /home/virtual/site128/fst/var/www/html/layout/No_Advertisements/functions.php:6 in /path/www/html/users.php on line 647
Warning: Cannot modify header information - headers already sent by (output started at /home/virtual/site128/fst/var/www/html/layout/No_Advertisements/functions.php:6 in /path/www/html/users.php on line 649"
Any idea what could be causing this and how it could be fixed? I'm taking the mod off the site until I can figure it out...
but than I think it caused a few errors (I'm pretty sure it was this mod)
When people try to log off or log on it doesn't let them and gives them a refresh page that says:
"Warning: Cannot modify header information - headers already sent by (output started at /home/virtual/site128/fst/var/www/html/layout/No_Advertisements/functions.php:6 in /path/www/html/users.php on line 647
Warning: Cannot modify header information - headers already sent by (output started at /home/virtual/site128/fst/var/www/html/layout/No_Advertisements/functions.php:6 in /path/www/html/users.php on line 649"
Any idea what could be causing this and how it could be fixed? I'm taking the mod off the site until I can figure it out...
18
23
Quote
Status: offline
Chalkhillian
Forum User
Chatty
Registered: 09/23/02
Posts: 67
You should do a search for 'headers already sent' - you will get a direct hit. Chances are that when you updated your php file, either you or your editor of choice placed some white space in the php file where it cannot be tolerated.
27
24
Quote
Status: offline
beewee
Forum User
Full Member
Registered: 08/05/03
Posts: 969
Location:The Netherlands, where else?
I want to use this nice trick, and just want to load a different CSS for each topic, would this work?
{
global $topic;
switch ($topic) {
case 'topic1':
$style = 'style1.css';
break;
case 'topic2':
$style = 'style2.css';
break;
default:
$style = 'style.css';
break;
}
$retval = '<link rel="stylesheet" type="text/css" href="/' . LB
. '$style;' . LB
. '"/>' . LB;
return $retval;
}
and in the header this:
I'm no developer, so I'm simply adapting excisting code without exactly knowing what I'm doing...
Dutch Geeklog sites about camping/hiking:
www.kampeerzaken.nl | www.campersite.nl | www.caravans.nl | www.caravans.net
Text Formatted Code
function style_emitCSS (){
global $topic;
switch ($topic) {
case 'topic1':
$style = 'style1.css';
break;
case 'topic2':
$style = 'style2.css';
break;
default:
$style = 'style.css';
break;
}
$retval = '<link rel="stylesheet" type="text/css" href="/' . LB
. '$style;' . LB
. '"/>' . LB;
return $retval;
}
and in the header this:
Text Formatted Code
<?php print style_emitCSS (); ?>I'm no developer, so I'm simply adapting excisting code without exactly knowing what I'm doing...
Dutch Geeklog sites about camping/hiking:
www.kampeerzaken.nl | www.campersite.nl | www.caravans.nl | www.caravans.net
26
21
Quote
Status: offline
Remdotc
Forum User
Chatty
Registered: 06/12/02
Posts: 55
it would be better if the theme code was set per topic , or per page , as defined by admin
you could also define this on the topic out link in lib-common.php
you could also edit the index.php and add a case statement
or for better compatablity and easier upgrades you could add the code to functions.php in your theme, then call the function in the header template
you could also define this on the topic out link in lib-common.php
you could also edit the index.php and add a case statement
or for better compatablity and easier upgrades you could add the code to functions.php in your theme, then call the function in the header template
22
27
Quote
Status: offline
beewee
Forum User
Full Member
Registered: 08/05/03
Posts: 969
Location:The Netherlands, where else?
Quote by Remdotc:for better compatablity and easier upgrades you could add the code to functions.php in your theme, then call the function in the header template
I believe that this thread started with this, so I already meant this.
Dutch Geeklog sites about camping/hiking:
www.kampeerzaken.nl | www.campersite.nl | www.caravans.nl | www.caravans.net
22
21
Quote
Status: offline
stevelucky
Forum User
Junior
Registered: 05/25/05
Posts: 17
this code changes the color based on topic. but what about static pages? i have a bunch of static pages and still want the header to change (images though, instead of colors). any ideas?
26
23
Quote
Status: offline
Dirk
Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany
Quote by stevelucky: this code changes the color based on topic. but what about static pages?
Same principle: Find out where on the site you are and emit CSS or HTML accordingly.
The PHP variable $_SERVER['PHP_SELF'], for example, contains .../staticpages/index.php when a static page is displayed.
bye, Dirk
27
28
Quote
All times are EST. The time is now 03:17 am.
- Normal Topic
- Sticky Topic
- Locked Topic
- New Post
- Sticky Topic W/ New Post
- Locked Topic W/ New Post
- View Anonymous Posts
- Able to post
- Filtered HTML Allowed
- Censored Content