Link Management in MT

Well, I took the plunge tonight and hacked away at the MT code. I wanted to implement a way to use the blog I've already got to manage the web links on my main page.

First I tweaked the <MTEntries> code as follows (in lib/MT/Template/Context.pm):

--- /usr/local/www/cgi-bin/blog/lib/MT/Template/Context.pm Thu Aug 22 14:04:57 2002 +++ Context.pm Wed Sep 25 22:32:09 2002 @@ -372,6 +372,37 @@ $saved_entry_stash = $ctx->{__stash}{entries} || []; $ctx->{__stash}{entries} = \@entries; delete $args->{category}; + } elsif ($cat_name =~ /^NOT (.*)$/) { + my @cats = split /\s+/, $1; + my %entries; + my $iter = MT::Category->load_iter ({ blog_id => $blog_id }, + { 'sort' => 'label', direction => 'ascend' }); + my %full_cats; + while (my $cat = $iter->()) { + $full_cats{$cat->label} = 1; + } + foreach my $cat (@cats) { + $full_cats{$cat} = 0; + } + for my $cat (keys %full_cats) { + if ($full_cats{$cat}) { + my $catgty = MT::Category->load({ label => $cat, + blog_id => $blog_id }) + or return $ctx->error("No such category '$cat'"); + my @place = MT::Placement->load({ category_id => $catgty->id }); + for my $place (@place) { + $entries{$place->entry_id}++; + } + } + } + my @ids = keys %entries; + for my $entry_id (@ids) { + my $entry = MT::Entry->load($entry_id); + push @entries, $entry if $entry->status == MT::Entry::RELEASE();+ } + $saved_entry_stash = $ctx->{__stash}{entries} || []; + $ctx->{__stash}{entries} = \@entries; + delete $args->{category}; } else { $cat = MT::Category->load({ label => $cat_name, blog_id => $blog_id })

Basically, what that does, in addition to being about to use AND and OR to pick the categories for MTEntries, is allow you to limit the categories with NOT, followed by one or more categories to exclude.

For example: <MTEntries category="NOT Links Web Local">

Then I added another MTEntries section to my Index Template for just the Links category.

It's certainly not perfect. This is only my first pass at things, and it is late at night. I'll have to take another look at it later this week when work lightens up a little bit.

The next thing I would like to do is enable something like a nested MTCategories within a MTEntries section. I'd like to be able to get a list of the categories within that group of entries so I could do some kind of heirarchical list of links.

UPDATE: You can download the complete Context.pm file here.

UPDATE AGAIN: Just because I'm lazy, I'll just go ahead and quote myself from the post on the MovableType Support forum:

I hate to reply to myself, but I figured I should mention what I just found out.

Apparently (maybe this is general knowledge, but I was unaware of it), when you limit MTEntries with category, the default days (i.e. taken from the blog config) is tossed out, and any days argument is ignored. I had to use lastn to keep my entire blog (all but the Links category) from being printed out. Luckily, my blog is still relatively new, so there aren't many entries. :)

I've looked through the code and I see where and why all this is happening, but I don't have the time to change things at the moment. I'll probably tackle it tonight.

1 Comment

This looks like any entries that don't have an assigned category are unavoidable excluded whenever exclusion is done. Is that so?

Leave a comment

About Me

I am a software developer for Six Apart living outside of Baltimore, MD. I have written a number of plugins for Movable Type, including the award winning MultiBlog, which has (as of MT 4) been integrated into the base application....
More...

Recent Entries

  • Minimalist plugins are fun!

    Last night I whipped up one of the smallest plugins I’ve ever written. It is so small in fact that I was able to stuff...

  • Feedburner Widget on MT News

    Movable Type News A WordPress 2.5 Upgrade Guide: And of course there are lots of third-party plugins for the MT dashboard, to integrate statistics and...

  • AD&D Monster Stats for the Presidential Canditates

    Charles Stross (scifi author, D&D nerd, and former perl columnist) posted Politics as she is Played with 3d6: The recent death of Gary Gygax, who...

  • Feedburner Widget 0.3

    At this point, I am really tempted to drop the ‘Widget’ from the name of the plugin, since it is doing so much more...

  • Feedburner Widget 0.2

    So I finally got around to updating the FeedburnerWidget plugin for MT 4.1 (since I finally got around to upgrading my install to MT 4.1)....

Close