Page 1 of 1
Category templates plugin with static pages
Posted: Wed Jun 25, 2008 9:47 pm
by carl_galloway
Can anyone tell me how to use this plugin?
Specifically what I want to do is assign a different template to certain static pages. I've allocated the templates in the categories admin screen, and in my static pages I've selected the category, but when I browse from static page to static page I don't see the different templates showing up.
Within the static pages plugin there is a readme that tells me to insert code into entries.tpl but I have no idea how this works. Anyone know what I'm doing wrong?
Re: Category templates plugin with static pages
Posted: Thu Jun 26, 2008 9:40 am
by garvinhicking
Hi!
That in fact is not what the plugin is invented for.
Even though static pages can be associated to categories, that only applies to related entries showing up. It does NOT put a "staticpage" INSIDE a category.
Thus, the category templates plugin does NOT apply to staticpages. Staticpages always use the default blog template.
The only way to change that is ... well, actually creating an event plugin that checks on the current staticpage and change the template depending on this.
If you don't need a GUI for this (which would be quit ehard to create) a simple event plugin like this could do:
Code: Select all
<?php
if (IN_serendipity !== true) {
die ("Don't hack!");
}
class serendipity_event_staticpagetemplates extends serendipity_event {
var $title = 'Static Page Templates';
function introspect(&$propbag) {
global $serendipity;
$propbag->add('name', $this->title);
$propbag->add('author', 'Garvin Hicking');
$propbag->add('version', '0.01');
$propbag->add('requirements', array(
'serendipity' => '1.3',
'php' => '4.3.0'
));
$propbag->add('event_hooks', array('genpage' => true));
}
function event_hook($event, &$bag, &$eventData, $addData = null) {
global $serendipity;
$hooks = &$bag->get('event_hooks');
if (isset($hooks[$event])) {
switch($event) {
case 'genpage':
switch($_SERVER['REQUEST_URI']) {
case '/pages/staticpage.html':
$serendipity['template'] = 'contest';
break;
case '/pages/staticpage2.html':
$serendipity['template'] = 'carl_contest';
break;
}
break;
}
}
}
}
Inside the $_SERVER['REQUEST_URI'] switch you need to add the URLs for your static pages and assign the template you want for it...
HTH,
Garvin
Posted: Thu Jun 26, 2008 9:54 am
by carl_galloway
Ah, that looks kinda groovy, I'll give that a try, thanks