Page 1 of 1

Mapping domains to styles and categories

Posted: Wed Jul 25, 2007 12:01 pm
by Kibiyama
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!

Re: Mapping domains to styles and categories

Posted: Wed Jul 25, 2007 1:44 pm
by garvinhicking
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:

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

Posted: Wed Jul 25, 2007 2:52 pm
by Kibiyama
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!)

Posted: Wed Jul 25, 2007 3:32 pm
by garvinhicking
Hi!
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?
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?

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;
        }
    }
}
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

Posted: Thu Jul 26, 2007 12:50 am
by Kibiyama
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. :wink: 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...)

Posted: Thu Jul 26, 2007 10:04 am
by garvinhicking
Hi!
Kibiyama 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 :(
I told you :-)

Mapp all domains to a single s9y installation and use the PHP code I gave you. :)
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?
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.

Rmemeber to enable the option "Autodetect HTTP-Host" in your s9y configuration.

HTH,
Garvin

Posted: Thu Jul 26, 2007 11:58 am
by Kibiyama
garvinhicking wrote:
Kibiyama 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 :(
I told you :-)

Mapp all domains to a single s9y installation and use the PHP code I gave you. :)
I think you misunderstood me there, but that's okay because I'm accomplishing it by using it in embed mode anyways. :D

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? :wink:

Posted: Thu Jul 26, 2007 12:18 pm
by garvinhicking
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 :)
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.
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. :-)

Best regards,
Garvin

Posted: Thu Jul 26, 2007 12:25 pm
by Kibiyama
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 :)
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. :lol:
I much more enjoy getting "paid" with active users who join our community. :-)
I'll take you up on this.

Posted: Thu Mar 20, 2008 9:08 pm
by diroddi
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

Posted: Fri Mar 21, 2008 11:27 am
by garvinhicking
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

Posted: Fri Mar 21, 2008 12:31 pm
by judebert
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.

Posted: Sat Mar 22, 2008 4:42 pm
by diroddi
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:

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;
        }
    }
}
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

Posted: Mon Mar 24, 2008 11:37 pm
by diroddi
If there isn't a way to use a new template entirely, is there a way to just swap to a different style sheet in the template folder?

Thanks

Posted: Tue Mar 25, 2008 9:34 am
by garvinhicking
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:

Code: Select all

{if $smarty.SERVER.HTTP_HOST == 'xyz'}
 <link rel="stylesheet" src="style1.css" />
{else}
 <link rel="stylesheet" src="style2.css" />
{/if}
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:

Code: Select all

$serendipity['smarty']->assign('hostname', $_SERVER['HTTP_HOST']);
and then query for {if $hostname} inside index.tpl...

HTH,
Garvin