Blog Selective Hacks

One of the biggest problems of simple hacks to the system is that they occur system wide, e.g. if you hacked the entry page to specify a default category, that category would become the default for all blogs on the system. This tutorial is a simple hack that will allow you to test the blog_id value and then conditionally display.

Open up lib/MT/App/ and search for

my $blog\_id = $app->{query}->param('blog\_id');

and add underneath it

my $blog\_id = $app->{query}->param('blog\_id');
$param->{"blog\_id\_$blog_id"} = 1;

Save and upload it to the appropriate location. That's it, now in your *.tmpl files, you can check the blog_id like so

my $blog\_id = $app->{query}->param('blog\_id');
$param->{"blog\_id\_$blog_id"} = 1;

where the contents of the IF will only display if the blog_id of the blog is 1.


Jeremy said:
on Jul 30, 2005 12:20 PM | Reply

Very useful! Oh ya, Happy Birthday!

Dan Wolfgang said:
on Jul 30, 2005 6:45 PM | Reply

Without a doubt, my default category hack has this problem. To be fair, though, it's still a step up: in my most-used weblog I have a default category set, and in every other weblog, I still have to select a category. In other words, it's no more difficult than before.

I'd also like to point out that using the edit_entry.tmpl and JavaScript to do this has the added benefit that--when upgrading don't need to worry about re-implementing the hack.

Yesterday I was contemplating exploring this problem with JavaScript. I should be able to parse the blog_id out of the URL and display a different default category for each weblog based on that. I think.

Arvind Satyanarayan said:
on Jul 31, 2005 12:28 PM | Reply

Jeremy: Thanks! :)

Dan: I'm not sure I understand what you mean, you can have multiple ifs so that you can set a default category for each of your weblogs, using the method you described, it would look something like this

<TMPL_IF NAME=BLOG_ID_1><option value="31">Elsewhere in our Life</option></TMPL_IF>
<TMPL_IF NAME=BLOG_ID_2><option value="32">Default Category</option></TMPL_IF>

does that answer your question? You're right about losing the hack once you upgrade, this would be a good BigPAPI plugin

xanax xr said:
on Nov 3, 2005 10:23 PM | Reply

Good articles.

Brett DeWoody said:
on Nov 8, 2006 11:05 PM | Reply

Great posting! But wondering if you could update it for MT3.3?

Thanks for the help in advance!


Jenny said:
on Dec 10, 2006 9:03 PM | Reply

cool hack

ljkarash said:
on Jan 2, 2007 6:11 AM | Reply

This is the hack I'm looking for, but I can't find the correct line in to edit in version 3.3

ljkarash said:
on Jan 2, 2007 6:21 AM | Reply

I found it! In MT3.3 in, it's in the subroutine: build_page underneath the line:

my $blogid = $app->param('blogid');