« Movable Type Plugins | Main

September 30, 2006

Teasing your entries

Well it’s been far too long since I posted a Movable Type tip, so here goes.

Have you ever wanted to display a blog entry one way on your main index page and another way on your archives page?

Movable Type 3.3x’s default templates now include CSS classes for the body HTML element on various pages published. (Not that you can’t do that with any previous version of MT; it’s just enabled by default now.) This is helpful, since it lets you create CSS rules that are context sensitive.

The body tag for my individual archive template starts like this.

<body class="layout-two-column-right individual-entry-archive">

By the way, there’s no mistake that there are two class names assigned here— this is completely legal as far as CSS is concerned.

So… what can you do with that? Well, for example, let’s say you sometimes want to include a “teaser” phrase that is intended to draw the person reading the summary on the main page (or the RSS feed of the post) to the rest of the entry.

Continue reading to find out how this is done.

Continue reading "Teasing your entries" »

March 17, 2004

Breaking your Entries

Here’s a quickie I’ve been meaning to post for a while. From time to time, people ask me, “Hey Brad— how do you do those dividers inbetween each post for a single day? How do you get MT to do that?”

Well, it’s not asked very often since I rarely post twice a day (or even once a day here lately). But here’s how you can do it, without using even one of my fantastic plugins.1

Continue reading "Breaking your Entries" »

February 5, 2004

MT-Textile does that???

Things you probably didn’t realize you could do with MT-Textile 2:

  1. Hyperlinks for Amazon, IMDB and Google searches. For example (search term can be placed after the last ‘:’, or will default to the hyperlinked text):
  2. Float images to the left and right; center stuff too:
    • !>/images/me.jpg! (floats image to right)
    • !</images/me.jpg! (floats image to left)
    • p=. !/images/me.jpg! (centers image in a paragraph)
  3. Use character macros for many international characters and symbols:
    • My 2{c|} becomes My 2¢
    • Resum{e’} becomes Resumé
    • {:)} becomes ☺
    • {umbrella} becomes {umbrella} (these are available if you have the ‘charnames’ Perl module as part of your Perl installation — if so, all available unicode character names can be expressed like this to produce that character)
  4. Write sloppy HTML for an XHTML formatted web site:
    • <br> becomes <br />
    • <img …> becomes <img …/>
    • <hr> becomes <hr />
  5. Make your text bigger and smaller using ++double plusses++ and —double minuses—
  6. Create definition lists using the “dl” block signature:
    • dl. term 1:This is the definition.
      term 2:another definition
  7. Combine HTML and Textile together. Textile tries to be pretty smart about HTML that’s mixed in with Textile content. If you find some egregious mishandling, please report it to the bug tracker.
  8. Footnotes
    • Indicating a footnote— add [number] to the end of a word (cannot be preceded by a space to be recognized).
    • Placing a footnote paragraph— use the “fnN.” block signature, where “N” is the number for the footnote you’re creating.
  9. Create some pretty fancy tables, complete with style sheet rules, header cells, row and column spanning, alignment and so on.
  10. Write valid XHTML. I would say that 99% of your weblog posts can be done using pure Textile markup. That is, without the need to write any HTML at all.
  11. Give things class. CSS class names can be assigned to most anything (of course, it’s up to you to write the CSS stylesheet):
    • p(first). Paragraph text will add a class="first" attribute to the paragraph tag.
    • %(logo)BigCorp% creates a “span” tag with the class “logo”.
  12. You can assign CSS id attributes too:
    • p(#copyright). Copyright (c) 2004
  13. You can even write style rules in there (thank goodness XHTML 2 has decided to preserve this option)
    • p{color:red;font-weight:bold}. Stuff I want in red and boldface.
  14. Define your language. Most things accept a language modifier:
    • p[fr]. Je suis tres bien. (makes a paragraph of French text)
    • bq[fr]. Je suis tres bien. (makes a blockquote of French text)
    • %[fr]Je suis tres bien.% (makes a span with French text)
  15. Colorize Java, PHP and Perl code (if you also have MT-CodeBeautifier installed):
    • bc[java]. public static void main(String[] args) {
          System.out.println(“Hello, world!”);
      }
    • @[php]echo “Hello, world!\n”;@
  16. Use the <$MTTextileOptions$> tag to control MT-Textile (this tag would be placed at the top of any MT templates that produce MT-Textile formatted data. You can combine multiple options within one tag):
    • <$MTTextileOptions head_offset="2"$> — translates “h1.” block signatures into <h3> tags instead (and so forth for h2, h3, etc.). This allows you to logically write “h1” as a top-level heading within your entry but have it render as an h3 tag upon publishing to your weblog.
    • <$MTTextileOptions preserve_spaces="1"$> — causes double-spaces to be changed to the HTML entity for an em-space (&8195;).
    • <$MTTextileOptions trim_spaces="1"$> — strips extra spaces from the end of each line.
    • <$MTTextileOptions smarty_mode="2"$> — lets you customize the SmartyPants handling. See the documentation for the SmartyPants for more.
    • <$MTTextileOptions flavor="html/css"$> — changes the output of Textile-created markup to be HTML 4.01 friendly.
  17. Write entire entries like this one without using angle brackets. (OK, I had to for the MT tag examples, but you know what I mean.)

July 27, 2003

Sitewide RSS

Well, it looks like this weblog is becoming just a Movable Type how-to blog. Well, in keeping with that theme, here’s a little “part two” companion piece for Doing your whole site with MT (one of my worst blog titles, ever).

Now that you’ve got your whole site MT-powered, what about your RSS feed? Chances are you, have one for your weblog, but what about one for everything? I’ve created one for my site, called sitewide.rss. It lets folks keep track of every update that happens to my site, whether it be part of my weblog or not.

To get it to work, you have to do a little bit of work. It’s not much though, and once you’ve done it, it’s easy to maintain.

Continue reading "Sitewide RSS" »

July 15, 2003

Doing your whole site with MT

Matt Haughey has a great article on how he uses Movable Type to do it all (apparently, Kottke does too… can’t wait to see his article).

Anyhow, I wanted to share a tidbit in that vein. I’ve just set this up recently, and I’m in the process of moving the rest of my static content to use it. What I did:

  1. Created a new Movable Type blog and named it “bradchoate.com: Static Content”.
  2. Deleted all the Index templates.
  3. Deleted all the archive templates, except for the Individual archive template.
  4. Made sure individual archives were enabled.
  5. Made the archive path the root directory of my web site.
  6. Created categories for each directory I want to create content for (category name = directory name)
  7. Used the following for the Individual Entry Archive filename template (specified on the “Archiving” page of your weblog configuration). Produces: “category/entry_title.html”:
    <$MTEntryCategory
        lower_case="1"$><MTIfNotEmpty
        var="EntryCategory">/</MTIfNotEmpty><$MTEntryTitle
        dirify="1"$>.html

So with this setup, instead of using your Index templates for your separate pages, they all become their own entry. This seems more appropriate to me. It also lets you use the excerpt and keywords field to store additional metadata about that particular page. So when you build, the individual file created for my “About” entry is named “about/index.php” since it has a category of “About” and an entry title “Index”.

You can do your individual file archive template any number of ways. The technique above will rely on the category assignment to define what directory to put the file. Here are some alternatives:

  1. Category defines directory (ie: “About/Something”), entry title is the full filename including extension (ie: “summer_vacation.html”): Produces: “about/something/summer_vacation.html”:
    <$MTEntryCategory
        lower_case="1"$><MTIfNotEmpty
        var="EntryCategory">/</MTIfNotEmpty><$MTEntryTitle$>
  2. Entry title is the full path and filename (ie: “about/something/summer_vacation.php”). Category isn’t used to name the file at all. Produces: “about/something/summer_vacation.php”:
    <$MTEntryTitle$>
  3. Category defines directory path (category label looks like “about/something/”). Entry title is descriptive (ie: “Summer Vacation”). Produces “about/something/summer_vacation.html”:
    <$MTEntryCategory$><$MTEntryTitle
        dirify="1"$>.html

The “IfNotEmpty” tag (provided through the IfEmpty plugin) allows you to test for no category assignment. If a category is not defined, then the ‘/’ prefix is left off the filename, so the file would go into the top directory of the weblog.

This benefits of all this are many. Because now I can use Textile formatting for any page of my web site. I can also make use of Movable Type’s search feature to search any page of my site instead of just my weblog content. I can also enable comments, trackback or whatever for any page I’d like.

May 3, 2003

Related Entries with MT-SQL

Related Entries Revisited. Adam Kalsey puts the power of MySQL full-text indexing and MT-SQL to work to provide a better “related entries” solution for Movable Type. A great example of how to use the

<MTSQLEntries>

tag.

April 5, 2003

Easy Amazon Links

If you’re lazy like me, you’d like to link to Amazon items and put your associate ID in there, but who remembers that URL format? With publishing systems like Movable Type, you shouldn’t have to remember, so let’s make MT do the work for us.

Ingredients:

Technique:

Define a pattern to match the Amazon URL (today they use the www.amazon.com/exec/obidos/tg/detail/-/ASINCODE/… So we use this to transform the regular Amazon link into an associate link:

<$MTSetVar name="amazon_id" value="your_amazon_associate_id"$>
<MTRegexDefine
  name="amazon_fixup1">s
   {^http://(www\.)?amazon\.com/exec/obidos/tg/detail/-/([a-zA-Z0-9]+)/.+$}
   {http://www.amazon.com/exec/obidos/ASIN/$2/<$MTGetVar name="amazon_id"$>/ref=nosim/}
</MTRegexDefine>
<MTRegexDefine
  name="amazon_fixup2">s
   {^http://(www\.)?amazon\.com/exec/obidos/ASIN/([a-zA-Z0-9]+)/.+$}
   {http://www.amazon.com/exec/obidos/ASIN/$2/<$MTGetVar name="amazon_id"$>/ref=nosim/}
</MTRegexDefine>

The next thing we need to do is create a macro that processes the ‘a’ tags in your entries, looking for hrefs that match that Amazon URL pattern:

<MTMacroDefine ctag="a" name="body_amazonfixup">
  <MTIfMatches
    expr="[MTMacroAttr name='href']"
    pattern="m|^http://(www\.)?amazon\.com/exec/obidos/.*|">
      <MTMacroAttr
        name="href"
        value="[MTMacroAttr name='href' regex='m/^amazon_fixup.*/']">
  </MTIfMatches>
  <MTMacroTag rebuild="1"><MTMacroContent></a>
</MTMacroDefine>

(Note that for each of these examples, you should remove any extra spaces inbetween the ‘MT’ tags so that you don’t get a lot of unwanted gaps in your HTML.)

In order to run this on your entries, just add the above markup to your index and/or archive templates — wherever you want them to function. A better idea would be to put all that into a custom template module and use the <MTInclude> tag to pull it in where it’s needed.

Finally, use the <MTMacroApply> tag around your entry body and entry more tags so that they are processed:

<MTMacroApply macro="body_amazonfixup">
  <MTEntryBody>
  <MTEntryMore>
</MTMacroApply>

That should do it. Maybe it’ll bump your Amazon referrals up a bit.

(For purposes of full disclosure, I have a meager investment in Amazon.com.)

February 19, 2003

Uninstalling the Sanitize plugin

Movable Type 2.6 incorporated my Sanitize plugin. So if you’ve upgraded to MT 2.6, you no longer need the plugin files. So here’s what you would do to remove them.

Again, these steps are only necessary if 1) you installed the Sanitize plugin on your pre-MT 2.6 blog; 2) you’ve since upgraded to Movable Type 2.6 or later.

  1. Locate the ‘sanitize.pl’ in your Movable Type plugins directory. Delete that file.
  2. Locate the ‘sanitize.pm’ file in your extlib/bradchoate directory. Delete that file.

Now, you may be wondering what to do about the

sanitize="..."

attributes you have scattered all over the place. Well, MT now has a ‘Sanitize’ field in the blog preferences you can use to define the allowable tags/attributes. This will be applied to all comments, foreign trackback data and so forth. If you use this preference field, you no longer need to add the ‘sanitize’ attribute to your MT tags. You can still use the ‘sanitize’ attribute if you ever want to override the default settings.

There is also a new mt.cfg configuration setting named “GlobalSanitizeSpec”. If you assign your list of tags/attributes here, this will be used for any blogs that don’t define their own Sanitize settings.

For more information about the Sanitize function in Movable Type 2.6, I invite you to read the fine manual.

December 16, 2002

Ask Brad

Well, for no good reason I felt I wanted to have a "Ask Brad" column on my site. I'm getting tired of thinking up subjects to post about so I'm letting my audience do that for me. LazyWeb syndrome I guess. Anyhoo, here's how I set it up with Movable Type. No complicated hacks required, honest.

Continue reading "Ask Brad" »

October 23, 2002

Valid RSS 0.91 feeds from Movable Type

John Gruber found (as I did recently) that the Movable Type RSS 0.91 template doesn't validate using the new RSS validator (kudos to Mark Pilgrim and Sam Ruby for developing the tool. Mine validates now.). John offers a way to fix it using a new custom plugin, <$MTrfc822BlogTimeZone$>. For those that already have my Regex plugin installed, you can do this instead:

<lastBuildDate><MTEntries lastn="1"><$MTEntryDate
  format="%a, %d %b %Y %H:%M:%S"$> <$MTBlogTimezone
  regex="s/://"$></MTEntries></lastBuildDate>
<pubDate><$MTDate
  format="%a, %d %b %Y %H:%M:%S"$> <$MTBlogTimezone
  regex="s/://"$></pubDate>

Or, if you don't have the time for any of this, just edit your RSS 0.91 template and replace the <MTBlogTimezone> tag with your 3-character time zone code (EST for example) or the numeric +/-HHMM offset equivalent. You could also switch to a RSS 1.0 or 2.0 format.

Categories

Archives

Powered by Movable Type