View Full Version : Is there a way to use PHP in templates
Hi there.
I wondered if there is a way to use PHP within the template structure of Pixelpost. This would be non-pixelpost code.
I need to do some time based PHP/CSS switch but don't have the skill to turn it into an addon.
Any ideas?
Thanks
Karl
Dkozikowski
12-14-2007, 06:15 AM
No, not directly.
You would have to make an addon to run any PHP code inside your templates.
Is there anyway you might be able to guide me in making this addon? I have the PHP code but don't know how to convert into addon.
This is the code in question: http://paste-it.net/5256
Thanks
Karl
austriaka
12-14-2007, 12:14 PM
quick and dirty (and not tested):
<?php
$addon_version = "1.0";
$addon_name = "daytime_css";
$addon_description = 'Change the CSS file according to time';
// time based Css Switch
$time = date("H");
$date = date("w");
if ($time >= 9 && $time < 18 && $date != 0) {
$myCSS = '<link rel="stylesheet" href="templates/'.$cfgrow['template'].'/styles/day.css" type="text/css" media="screen" />';
}
else {
$myCSS = '<link rel="stylesheet" href="templates/'.$cfgrow['template'].'/styles/night.css" type="text/css" media="screen" />';
}
$tpl = ereg_replace("<DAYTIME_CSS>",$myCSS,$tpl); // use instead of <link rel="stylesheet" href="templates... in page header
?>
Save it as daytime_css.php in the addons folder and use <DAYTIME_CSS> instead of the <link rel="stylesheet" href="templates... in page header.
Supposed you have a folder called "styles" within your template directory
Hi austriaka+,
Many many thanks for that. I will check it out once home from the day job :)
Thank you
Karl
vBulletin® v3.7.3, Copyright ©2000-2013, Jelsoft Enterprises Ltd.