FAQ: How to hide a Category from the Start Page
Question
I have a couple of categories in my weblog. By default, these are listed on the start page. I want to hide a certain category. How can I do that?
Answer
The start page is based on the »Main Index Template«. We have to change that template for making categories disappear.
If you do not know the term »Main Index Template«, then please have a look at FAQ: Explaining the Templates. Moreover, we will need the Compare Plugin. If you do not know it, or it has not yet been installed, please read the entry Comparison needed for conditional Generation.
Open your Movable Type project. Click »Templates« in the left navigation bar. A list of templates will be shown. Click on the »Main Index Template«. In the following dialog, the template body is shown. It is the code that makes up the generated HTML code.
Now scroll down, until you see the following lines.
<div id="categories">
<h2>Categories</h2>
<MTSubCategories>
<MTSubCatIsFirst><ul></MTSubCatIsFirst>
<MTIfNonZero tag="MTCategoryCount">
<li><a href="<$MTCategoryArchiveLink$>" title="<$MTCategoryDescription$>"><MTCategoryLabel></a>
<MTElse>
<li><MTCategoryLabel>
</MTElse>
</MTIfNonZero>
<MTSubCatsRecurse max_depth="3">
</li>
<MTSubCatIsLast></ul></MTSubCatIsLast>
</MTSubCategories>
</div>
This is the code that is responsible for creating the category listing on the right side of your weblog's start page. It is a recursive walk through all your categories.
If you are interested, here are some remarks about this code. You can skip this list, if you just want to proceed with the answer to your question.
- A div-tag is created. Its id is "categories", which can be found in the CSS.
- The text "Categories" is printed as an h2-tag.
- The MTSubCategories starts a loop. It will loop though all categories, starting at the top.
- Only if the category is the first one on the current level, an ul-tag is printed.
- Then a comparison is done. We check, whether the number of entries in the categories is zero or not.
- If it is not zero, the category label will be printed as an a-tag within the li-tag. It can be used for jumping to the category archive.
- If it is zero, the category label will be printed as simple text within the li-tag. As no entries exist for this category, there will not be a category archive. So we do not need an a-tag.
- Then we descend down the category hierarchy. Maybe the category has sub-categories. If it has, we will start the loop again with the first child of the current category.
- The li-tag is closed.
- If this is the last category of the current level, the ul-tag is closed.
- The div-tag is closed.
As an example let us change the above code, so that the category "Printers" is skipped. For achieving this, we just have to embrace the main part of the section with a comparison: only if the category label is not equal to "Printers", then do the following.
The change is very small. I highlighted it with a bold typeface.
<div id="categories">
<h2>Categories</h2>
<MTSubCategories>
<MTIfNotEqual a="[MTCategoryLabel]" b="Printers">
<MTSubCatIsFirst><ul></MTSubCatIsFirst>
<MTIfNonZero tag="MTCategoryCount">
<li><a href="<$MTCategoryArchiveLink$>" title="<$MTCategoryDescription$>"><MTCategoryLabel></a>
<MTElse>
<li><MTCategoryLabel>
</MTElse>
</MTIfNonZero>
<MTSubCatsRecurse max_depth="3">
</li>
<MTSubCatIsLast></ul></MTSubCatIsLast>
</MTIfNotEqual>
</MTSubCategories>
</div>
If you had several categories that should be skipped, simply duplicate the MTIfNotEqual and the corresponding ending tag several times.
...
<MTIfNotEqual a="[MTCategoryLabel]" b="Printers">
<MTIfNotEqual a="[MTCategoryLabel]" b="Monitors">
...
</MTIfNotEqual>
</MTIfNotEqual>
...
With this, you will nest one comparison within another comparison, saying: if the category is not "Printers" and it is not "Monitors" then do the following.
mgs
Feedback is welcome!
What do you think about this entry? Was it interesting or boring? I would like to hear your comments. If the text was helpful, please consider setting a link to http://www.movable-type-weblog.com/.
No spam please!
For protecting this weblog I have installed the MT-Approval Plugin. You have to view a new comment in preview mode, before it is saved on the server. Moreover, I will view your comment manually, before it is published. You can find more information on the subject in the entry Weblog Spamming Basics.
With an active TypeKey session, your comment will be published immediately.
Post a new comment
TypeKey has temporarily been disabled at this location. Please create your comment without using TypeKey or log in from the preview dialog.
Comment
Hugh Craig | April 27, 2005 10:06 AM
Exactly what I needed right now! Continue writing those introductions. There are a lot of people out there, not knowing Movable Type perfectly.
Comment
bruce21 | April 28, 2005 08:32 AM
Excellent tutorials!!!
I was going to write some, even though I never seem to have the time. Glad I didn't, yours are better than mine would have been without a LOT of work. I will certainly link to you from my site, this kind of thing has been sadly lacking in the MT community.
Well done!
Thanks a lot for your encouraging words.
If you do link from your site, do not forget to take part in the 'Link and Win' drawing. The fist drawing will take place on June 6th. The first EUR 50 are waiting for somebody out there.
Comment
Joki | February 8, 2006 02:40 AM
This just simply hide the link to the categories ... Is there a way to truely protect this categories from being view when they know the link?
Comment
Michael G. Schneider | February 8, 2006 11:06 AM
How do you want to make the URLs available? Password protection? Just do some searching with MTLookup. Simply enter
password protect
into the above search box. There are several techniques discussed on several websites.
Comment
Matt | September 13, 2006 11:35 PM
Instead of Sub, my template has the tag:
MTTopLevelCategories
does this matter? It doesnt seem to be hiding the category when I use it like this:
MTTopLevelCategories
MTIfNotEqual a="[MTCategoryLabel]" b="Sidebar"
(Note:tag open/close removed so you can see the code)

