Mapping domains to styles and categories
Mapping domains to styles and categories
I've got multiple domains on the same hosting account, and want to have each domain (except the root) be sort of a hub for specific content.
So, I've got one main blog in the root:
myDevelopmentBlog
...which publishes content in any of several categories.
Then, a domain, say www.myProject.com, should show visitors the content relevant to that specific project. It should also have a style specific to the project.
I think can access the categories alright by accessing index.php?/categories/ (am I correct?) but I have no idea how to do the styles. Edit: Come to think of it, I really haven't any idea how to do the first part, either. I just started web development about 4 days ago...
Before this, I was trying to install a separate blog on every domain (or rather, every folder on the server) and that did NOT go well, which is just as well since synchronizing everything seemed like a pain in the ass to begin with.
Am I correct in assuming that one central installation is the optimal way to solve this?
Thanks for any help!
So, I've got one main blog in the root:
myDevelopmentBlog
...which publishes content in any of several categories.
Then, a domain, say www.myProject.com, should show visitors the content relevant to that specific project. It should also have a style specific to the project.
I think can access the categories alright by accessing index.php?/categories/ (am I correct?) but I have no idea how to do the styles. Edit: Come to think of it, I really haven't any idea how to do the first part, either. I just started web development about 4 days ago...
Before this, I was trying to install a separate blog on every domain (or rather, every folder on the server) and that did NOT go well, which is just as well since synchronizing everything seemed like a pain in the ass to begin with.
Am I correct in assuming that one central installation is the optimal way to solve this?
Thanks for any help!
-
garvinhicking
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Re: Mapping domains to styles and categories
Hi!
What you can do quite easily is this: Install the "Extended options/templates for categories" plugin from Spartacus. With that you can assign a custom template to each category.
Then you'll either need a custom PHP code that sets a serendipity category variable depending on the host you are using. The best way to do this is in the serendipity_config_local.inc.php file:
so for each host you have, you add one code segment that assigns the proper categoryid to your serendipity blog.
HTH,
Garvin
What you can do quite easily is this: Install the "Extended options/templates for categories" plugin from Spartacus. With that you can assign a custom template to each category.
Then you'll either need a custom PHP code that sets a serendipity category variable depending on the host you are using. The best way to do this is in the serendipity_config_local.inc.php file:
Code: Select all
if ($_SERVER['HTTP_HOST'] == 'MyFirstCategoryHost.com') {
$_REQUEST['serendipity']['category'] = 2;
} elseif ($_SERVER['HTTP_HOST'] == 'MySecondCategoryHost.com') {
$_REQUEST['serendipity']['category'] = 3;
} ...
so for each host you have, you add one code segment that assigns the proper categoryid to your serendipity blog.
HTH,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Thanks for the fast response!
This seems like a good way of doing it. Though, won't visitors of the main blog change styles when they click an entry for a specific project? Is there a good way around that?
Perhaps if the styles were dependent on the host rather than the category, if that's possible? My forte is C++, I'm rather impotent in PHP. (I think the dollar signs scare me off!)
This seems like a good way of doing it. Though, won't visitors of the main blog change styles when they click an entry for a specific project? Is there a good way around that?
Perhaps if the styles were dependent on the host rather than the category, if that's possible? My forte is C++, I'm rather impotent in PHP. (I think the dollar signs scare me off!)
-
garvinhicking
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Hi!
You can fix parts of this with custom Serendipity Plugins or PHP similar to the one I posted. You can create your own little plugin that sets a style depending on the HTTP host:
Save that plugin as plugins/serendipity_event_hosttemplates/serendipity_event_hosttemplates .php and install it, and then you only need to change the IF-statement where you detect HTTP-Hosts and set the templates.
Best regards,
Garvin
If you use a specific template for a category, yes, clicking on an entry will then format this entry in the layout for the category its posted in. But that should be the desired functionality, right?This seems like a good way of doing it. Though, won't visitors of the main blog change styles when they click an entry for a specific project? Is there a good way around that?
You can fix parts of this with custom Serendipity Plugins or PHP similar to the one I posted. You can create your own little plugin that sets a style depending on the HTTP host:
Code: Select all
<?php
class serendipity_event_hosttemplates extends serendipity_event {
function introspect(&$propbag) {
$propbag->add('name', 'Host Templates');
$propbag->add('event_hooks', array('genpage' => true));
}
function event_hook($event, &$bag, &$eventData, $addData = null) {
global $serendipity;
$hooks = &$bag->get('event_hooks');
if ($event == 'genpage') {
if ($_SERVER['HTTP_HOST'] == 'yourFirstDomain') {
$serendipity['template'] = 'carl_contest';
} elseif ($_SERVER['HTTP_HOST'] == 'yourSecondDomain') {
$serendipity['template'] = 'contest';
}
return true;
}
}
}
Best regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Thanks for all the help so far, but I can't test that because I don't know how to make myProject.com appear as mainSite.com/index.php?/categories/myCategory 
*sigh* I hate not knowing things.
By the way, I want the templates to be specific to the site rather than the category because I have navigation buttons specific to the site (like "about.html") inside the templates. Is that bad?
Edit: I played around with embedding Seredipity, and that seems to be more like what I need. Most of the differences in the templates I can do with HTML and CSS.
Sorry to make you engineer half my site for me.
This whole thing has lit a fire under me to learn PHP, though.
Thanks for all your help!
(and you can bet I'll be back to ask more questions sometime soon, hehe...)
*sigh* I hate not knowing things.
By the way, I want the templates to be specific to the site rather than the category because I have navigation buttons specific to the site (like "about.html") inside the templates. Is that bad?
Edit: I played around with embedding Seredipity, and that seems to be more like what I need. Most of the differences in the templates I can do with HTML and CSS.
Sorry to make you engineer half my site for me.
Thanks for all your help!
(and you can bet I'll be back to ask more questions sometime soon, hehe...)
-
garvinhicking
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Hi!

Mapp all domains to a single s9y installation and use the PHP code I gave you.
Rmemeber to enable the option "Autodetect HTTP-Host" in your s9y configuration.
HTH,
Garvin
I told youKibiyama wrote:Thanks for all the help so far, but I can't test that because I don't know how to make myProject.com appear as mainSite.com/index.php?/categories/myCategory
Mapp all domains to a single s9y installation and use the PHP code I gave you.
That's okay, but you need to remember that you need to have different filenames like "about-site1.html" and "about-site2.html", becaues you cannot use the same filename for a single s9y installation, no matter on which site it runs on.By the way, I want the templates to be specific to the site rather than the category because I have navigation buttons specific to the site (like "about.html") inside the templates. Is that bad?
Rmemeber to enable the option "Autodetect HTTP-Host" in your s9y configuration.
HTH,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
I think you misunderstood me there, but that's okay because I'm accomplishing it by using it in embed mode anyways.garvinhicking wrote:I told youKibiyama wrote:Thanks for all the help so far, but I can't test that because I don't know how to make myProject.com appear as mainSite.com/index.php?/categories/myCategory
Mapp all domains to a single s9y installation and use the PHP code I gave you.
Well, I got off to a rocky start, but with some grit, determination, and a few pushes in the right direction (and 9 re-installs), I think I've got it up and running pretty well.
Check it out!
Main site: http://lessthanthree.vg/
Project site (only one up so far): http://fighthouse.vg/
It's a work-in-progress. (no CSS for blog yet, so it's just going off the CSS for the page)
Thank you so much, you've been a tremendous help, and Serendipity itself has been a wonderful piece of software so far. Maybe once I get out from under student loans or land a half-decent job, I'll be able to repay you.
By the way, don't you just love over-zealous newbies?
-
garvinhicking
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Hi!
Aah, okay, I'm sorry, I misread the last parts of your statement then.
Glad you got it to work that way. Actually the PHP-solution would be better in terms of performance, and would allow easier templating - but whatever works best for you is fine also

Best regards,
Garvin
Aah, okay, I'm sorry, I misread the last parts of your statement then.
Glad you got it to work that way. Actually the PHP-solution would be better in terms of performance, and would allow easier templating - but whatever works best for you is fine also
Thanks a lot for saying this, it means a lot to me. Hope you'll have much fun with Serendipity! You don't need to repay me in terms of money, I much more enjoy getting "paid" with active users who join our community.Thank you so much, you've been a tremendous help, and Serendipity itself has been a wonderful piece of software so far. Maybe once I get out from under student loans or land a half-decent job, I'll be able to repay you.
Best regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Maybe I'll end up doing it that way after I learn more about PHP. And HTML. And CSS. And Linux. And Apache. I just started 6 days ago, after all.garvinhicking wrote:Glad you got it to work that way. Actually the PHP-solution would be better in terms of performance, and would allow easier templating - but whatever works best for you is fine also
I'll take you up on this.I much more enjoy getting "paid" with active users who join our community.
I'm trying to implement the serendipity_event_hosttemplates mentioned above and the template is not being changed.
I created the plugin, installed it and have enabled Autodetect HTTP-Host in the configuartion. The host I'm testing for is the in the IF statement but the template used is my default template.
Is there anything else I need to do to make this worK?
Thanks
I created the plugin, installed it and have enabled Autodetect HTTP-Host in the configuartion. The host I'm testing for is the in the IF statement but the template used is my default template.
Is there anything else I need to do to make this worK?
Thanks
-
garvinhicking
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Hi!
You mean serendipity_event_categorytemplates?
Where exactly did you place which PHP code? And did you set a different template for the category in the category management?
Does it change the templates when you switch categories, independent from the HTTP host you use?
Regards,
Garvin
You mean serendipity_event_categorytemplates?
Where exactly did you place which PHP code? And did you set a different template for the category in the category management?
Does it change the templates when you switch categories, independent from the HTTP host you use?
Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
I'm pretty sure he installed the mini-plugin you created above, hosttemplates.
You mentioned you installed it; did you remember to install it in the configuration page? (From admin, click "Configure Plugins", click "Install new event plugin", and click the icon next to "Host Templates".)
You might try adding a debugging statement printing out the $_SERVER['HTTP_HOST'] just before the if statement. That way you can tell if (and why) it's not matching.
We can definitely make this work. Just gotta figure out what's messing up.
You mentioned you installed it; did you remember to install it in the configuration page? (From admin, click "Configure Plugins", click "Install new event plugin", and click the icon next to "Host Templates".)
You might try adding a debugging statement printing out the $_SERVER['HTTP_HOST'] just before the if statement. That way you can tell if (and why) it's not matching.
We can definitely make this work. Just gotta figure out what's messing up.
Your right., I did install hosttemplates, via 'Install new event plugin' and it's listed in my installed plugins. I modified the plugin like so:
The problem I'm having now is that it doesnt work as expected. When the template changes, it retains parts of the default template style chosen via Configuration > Manage Styles. I have tried clearing the browser cache with same result.
How can I implement this type of functionality and be certain that only the new template being set is used?
Thanks
Code: Select all
//$_SESSION['affiliate_blog_style'] = 'jlbg_brown';
class serendipity_event_hosttemplates extends serendipity_event {
var $title = 'Host Templates';
function introspect(&$propbag) {
$propbag->add('name', 'Host Templates');
$propbag->add('event_hooks', array('genpage' => true));
}
function event_hook($event, &$bag, &$eventData, $addData = null) {
global $serendipity;
$hooks = &$bag->get('event_hooks');
if ($event == 'genpage') {
$serendipity['template'] = $_SESSION['affiliate_blog_style'];
return true;
}
}
}
How can I implement this type of functionality and be certain that only the new template being set is used?
Thanks
-
garvinhicking
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Hi!
I've just visited yourr two mentioned URLs, and they seem to properly change their layout!
Can you describe what exactly happens that does not work correctly, and maybe a URL to try/reproduce this with?
Basically, with this plugin, the $serendipity['template'] should change for everything...of course, the other way is to edit your index.tpl template file and add Smarty "IF" branches inside to use different stylesheets, like:
It might be that this smarty var is not available, in this case you would need to add/create a config.inc.php file to your template directory with this:
and then query for {if $hostname} inside index.tpl...
HTH,
Garvin
I've just visited yourr two mentioned URLs, and they seem to properly change their layout!
Can you describe what exactly happens that does not work correctly, and maybe a URL to try/reproduce this with?
Basically, with this plugin, the $serendipity['template'] should change for everything...of course, the other way is to edit your index.tpl template file and add Smarty "IF" branches inside to use different stylesheets, like:
Code: Select all
{if $smarty.SERVER.HTTP_HOST == 'xyz'}
<link rel="stylesheet" src="style1.css" />
{else}
<link rel="stylesheet" src="style2.css" />
{/if}
Code: Select all
$serendipity['smarty']->assign('hostname', $_SERVER['HTTP_HOST']);
HTH,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/