Creating a "Sticky" Entry

Sometimes I want to make a post "sticky" so it stays at the top of my entry list for an extended length of time, even after posting newer entries. There are several ways to accomplish this.

One, perhaps the simplest, is to post-date the "sticky" entry so that it will stay in place as long as that date is still in the future or no entry has usurped it's place by post date.

Another option is to just hard-code the sticky text into your index template where you want it. (yuck, but it works)

A third option and my preferred method is to use the MTEntry plugin which gives you the MTEntry tag, allowing you to call one specific entry id...

Place your code above the regular MTEntries code. You can see on my main index that I have also created a div named sticky and, in my stylesheet, styled it with a border and alternate background color. If a sticky post is not currently displayed on my main index, see this screenshot to see the styling I use. Here's one way to code this:

<MTEntry id="77"> <div id="sticky"> <h3 id="a<$MTEntryID pad="1"$>"><$MTEntryTitle$></h3> <$MTEntryBody$> </div> </MTEntry>

Last, but not least, is to create a category called "sticky" or "announcements" and insert the MTEntries code calling only that category into your main index template above your normal MTEntries code. Your announcement entries can be categorized accordingly and, voila!, your most recent post from that category will remain in place until a new announcement replaces it.
CODE SAMPLE:

<MTEntries category="sticky"> <div id="sticky"> <h3 id="a<$MTEntryID pad="1"$>"><$MTEntryTitle$></h3> <$MTEntryBody$> </div> </MTEntries>

If you do not want your "sticky" post to be duplicated in your regular entries, you can use the CatEntries plugin which allows you to include or exclude specific categories from your entries. Use this in your regular MTEntries tag:

<MTCatEntries lastn="7" exclude="sticky">
with closing tag
</MTCatEntries >
This will cause all entries except those in the excluded category to be displayed. Additionally, you might wish to hide the "sticky" category from your category lists. I suggest the MTFilterCategories plugin to get the job done easily.

About this Entry

This page contains a single entry by Kate published on April 16, 2005 1:13 PM.

Kill TrackbackRSS was the previous entry in this blog.

mt3.16 haiku is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.