Specifying a Default Primary Category


Published on July 25, 2005 at 1:28 PM EST
In the Tutorials category.

When running Movable Type out-of-the-box, a primary category isn’t picked when you start a new entry. Having a default category can help ensure that entries are categorized correctly and—if one category is most popular—eliminate a little work, too. It’s…

category.gif

When running Movable Type out-of-the-box, a primary category isn’t picked when you start a new entry. Having a default category can help ensure that entries are categorized correctly and—if one category is most popular—eliminate a little work, too.

It’s a quick and simple hack to the edit_entry.tmpl file to make this happen. It’s also another good opportunity to use alternate templates (instructions are available).

Choose a Default Category

First, you’ll need to pick a category to be the default, and select the HTML that goes with it. I decided to setup the “Elsewhere in Our Life” category as the default, and will use this as an example.

http://www.eatdrinksleepmovabletype.com/upload/2005/10/view-source-thumb.gif

Log into MT and click “New Entry,” just as though you were going to start something new. Right-click on the page and choose “View Source,” “View Page Source,” or similar. Scroll down until you find the category listing, which’ll look something like in the thumbnail at the right. Find the category you want to be the default and copy that line. Mine looks like this:

<option value="31">Elsewhere in our Life</option>

“Elsewhere in our Life” is the name of the category, and “31” is the number MT has applied to it.

Set the Default Category

Next, you’ll need to open your edit_entry.tmpl template file. I recommend setting up alternate templates for this, but if you don’t want to you’ll find edit_entry.tmpl in the folder tmpl/cms/.

Search for “Primary Category” or scroll down to line 183. You’ll see some code that looks like this:

<TMPL_IF NAME=DISP_PREFS_SHOW_CATEGORY>
<label for="category_id"><MT_TRANS phrase="Primary Category"></label><br />
<select name="category_id" id="category_id" tabindex="2" onchange="doAddCategory(this)">
<TMPL_LOOP NAME=CATEGORY_LOOP>
<TMPL_IF NAME=CATEGORY_LABEL>

This is where you’ll add your default category. In the example below, I’ve bolded the addition.

<TMPL_IF NAME=DISP_PREFS_SHOW_CATEGORY>
<label for="category_id"><MT_TRANS phrase="Primary Category"></label><br />
<select name="category_id" id="category_id" tabindex="2" onchange="doAddCategory(this)">
<option value="31">Elsewhere in our Life</option>
<TMPL_LOOP NAME=CATEGORY_LOOP>
<TMPL_IF NAME=CATEGORY_LABEL>

Save the template. Go back to the MT interface and the New Entry page. You should see your default category in place!

This article is tagged as: Alternate Templates, Tutorials

Comments

So far, there are 3 comments and Trackbacks on this entry. Add yours!

1

Interesting! But what if you have more than one weblog on a system? Will all weblogs default to whatever category ID you set in the edit_entry.tmpl? This could be a bit problematic… What would you suggest to do this on a per-weblog basis?

2

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…

3

Any chance you’ve figured out how to do this for the bookmarklet template (bm_edit.tmpl)? This simple hack doesn’t work because the category listing is only instantiated when the user selects the name of the weblog.

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

 
 
 


TrackBack URL for Specifying a Default Primary Category:
http://www.eatdrinksleepmovabletype.com/cgi-bin/mt/mt-tb.cgi/312