Categories
Movable Type

Rebuilding Empty Categories

One thing that I've seen requested from time to time is the ability to rebuild empty categories. The problem is that Movable Type doesn't make this easy to do because when you rebuild entries, the rebuild routine loops over the entry table in order to determine which categories…

One thing that I’ve seen requested from time to time is the ability to rebuild empty categories. The problem is that Movable Type doesn’t make this easy to do because when you rebuild entries, the rebuild routine loops over the entry table in order to determine which categories to rebuild. If a category doesn’t have entries, it isn’t selected for the rebuild process. But that doesn’t mean that you can’t get around this limitation.

Luckily, the routine that actually does the building doesn’t care if the category is empty. By submitting the category to the routine, you can build an empty category page, for instance as a placeholder. Your code might look something like this:

  require MT::Category;
  my $test = MT::Category->load(9);
  $app->publisher->_rebuild_entry_archive_type (
  Blog => $blog,
  Category => $test,
  ArchiveType => 'Category',
  );

There is nothing magical about the number 9 in the example above – it is just the number I was using of an empty category. You would likely want to iterate over all categories, or retrieve one from the stash or something.

If you need help putting this into a callback or plugin, let me know. As a Movable Type Consultant, it is what I do, after all.

2 replies on “Rebuilding Empty Categories”

That’s the “You would likely want to iterate over all categories…” part.

For instance, if you want it to build all categories every time the site is published, you would create a callback that gets triggered in that instance, which then loads each category and calls the above code with the appropriate category code for each (replacing the example 9, as described).

Also as mentioned, I provide Movable Type Consulting through my business.

Contact me there if this isn’t clear enough and you’d like me to provide you a quote for doing the work for you.

Comments are closed.