Recently in Tips & Tricks Category

Increase Basename Length for SEO URLs

| 2 Comments

Well authored urls make for good SEO. One the simplest ways to do this is to write good titles to your entries and then MT will dirify the title to create a basename from which the url to the entry is created. But if your entry title is longer than 100 characters, the rest of the url is clipped.

Good news! Basename can be increased to 250 characters. As it seems that most people would prefer unclipped urls to long urls, I added a feature request to increase the default to the max of 250 characters. Then if a user prefers to have smaller urls, they can modify this setting.

To change your default, navigate to Preferences > Entry Settings, and change Basename Length to your desired length.

Entry Settings - Adventures in Movable Type | Movable Type Pro

Wondering how to customize the Global Templates “Profile Edit Form” or the “Registration Form”? Here’s a few options.

Basic reordering of custom fields is possible on the edit profile page in the MT app. Using the “Reorder Fields” in the “related content” sidebar.

If you want to intersperse custom fields between default fields it’s a little more trickey; by default all built-in fields are output and then all custom fields are output in the order specified on the edit profile page.

The <mt:AuthorCustomFields> tag should be used for this but as of MT4.2 I couldn’t get it to work on the edit profile or registration form, so for now you can use the same loop that currently outputs the custom fields, but limit the output with an <mt:if> tag. Here’s an example of how you can do it…

Description

Use three loops each containing an conditional tag (if or unless) to limit the output of the loop by custom field basename. The first and second loops limit by checking to see if the basename is equal to a value. The third loop outputs all fields except the the two I’ve specified (if fields are duplicated on the form the html will be invalid and only the second input’s value will be saved)

Example

Thi example uses the custom fields “Level” and “Bio”. You may place each loop anywhere in the Edit Profile template’s form.

<mt:Loop name="field_loop">
   <mt:If name="__first__">
   <input type="hidden" name="_type" value="author" id="obj_type" />
   <input type="hidden" name="customfield_beacon" value="1" id="customfield_beacon" />
   </mt:If>
   <mt:if name="basename" eq="level">
   <!-- start-customfield_<$mt:Var name="basename"$> -->
   <mtapp:setting
   id="$field_id"
   label="$name"
   hint="$description"
   shown="$show_field"
   show_hint="$show_hint"
   required="$required">
   <$mt:Var name="field_html"$>
   </mt:App:Setting>
   <!-- end-customfield_<$mt:Var name="basename"$> -->
   </mt:if>
</mt:Loop>

<!-- Default field here -->

<mt:Loop name="field_loop">
   <mt:If name="__first__">
   <input type="hidden" name="_type" value="author" id="obj_type" />
   <input type="hidden" name="customfield_beacon" value="1" id="customfield_beacon" />
   </mt:If>
   <mt:if name="basename" eq="bio">
   <!-- start-customfield_<$mt:Var name="basename"$> -->
   <mtapp:setting
   id="$field_id"
   label="$name"
   hint="$description"
   shown="$show_field"
   show_hint="$show_hint"
   required="$required">
   <$mt:Var name="field_html"$>
   </mt:App:Setting>
   <!-- end-customfield_<$mt:Var name="basename"$> -->
   </mt:if>
</mt:Loop>

<!-- Default field here -->

<mt:Loop name="field_loop">
   <mt:If name="__first__">
   <input type="hidden" name="_type" value="author" id="obj_type" />
   <input type="hidden" name="customfield_beacon" value="1" id="customfield_beacon" />
   </mt:If>
   <mt:unless name="basename" like="(bio|level)">
   <!-- start-customfield_<$mt:Var name="basename"$> -->
   <mtapp:setting
   id="$field_id"
   label="$name"
   hint="$description"
   shown="$show_field"
   show_hint="$show_hint"
   required="$required">
   <$mt:Var name="field_html"$>
   </mt:App:Setting>
   <!-- end-customfield_<$mt:Var name="basename"$> -->
   </mt:unless>
</mt:Loop>

Aaron Vanderzwan offers a similar solution and Elise summarized the solution on LearningMT4.com

MTML Code in Entries or Pages

| No Comments

You want a page with a title and a few paragraphs… but you also want a list of entries as a part of the page. How to do it?

You can use the mteval global modifier, but in the note I added there due to the way MT is optimized to publish, using the mteval global modifier isn’t really an option for most cases.

But there is a better way. The concept is to use an index template but to build the content of the template by combining content from a page and from entries.

Here’s how to create a page for entries tagged as events:

  1. Create a page titled “Events”.

    Add the body text “These are our events”.

    Add the tag “@eventpage”.

  2. Create a few entries with sample event info and add the tag “event”.

  3. Create a new index template called “Events” and set the output file as events.html.

    In the body of the template add this code to list the most recent 10 events tagged with the private tag “@event”:

    <mt:Pages tag="@eventpage" lastn="1">
        <h1><$mt:EntryTitle$></h1>
        <$mt:EntryBody$>
    </mt:Pages>
    <ul>
    <mt:Entries tag="event" lastn="10">
        <li><a href="<$mt:EntryPermalink$>"><$mt:EntryTitle$></a></li>
    </mt:Entries>
    </ul>
    
  4. Save the index template… and then publish the index template.

That’s it. =)

Automation is awesome! This script I use to set up a new MT instance probably saves me 15-20 hours a year, that 2-3 workdays.

I use the below shell script to:

  • checkout target release of MT
  • checkout addons (Packs [ProPack, MTCS, Enterprise], static files, & Tristan Theme)
  • checkout addons themes (Tristan
  • issue make
  • set up a static directory for the release
  • set permissions
  • create a mt-config.cgi file
  • and finally… open the release in TextMate

If you have an suggested improvements, please comment below!

Usage

Simple command does the above

$ makemt 41

Full command

$ makemt target-release {local-dir} {addons-release}

Note: If you are not using the addons (or don’t have access to them) you’ll need to comment out the portions of the script containing addons_branch.

Script

#!/usr/bin/env sh

# setup a new MT release
function makemt ()
{
    # usage: makemt target_release local_release_dir addons_branch
    # example: makemt 40 r40
    # target_release = svn repo name
    # local_release_dir = local release dir to place this repo
    target=${1};
    local_release_dir=${2};
    if [ ! $local_release_dir ]; then
        local_release_dir=$target;
    fi
    addons_branch=${3};
    if [ ! $addons_branch ]; then
        addons_branch="cal";
    fi
    if [ $target ]; then
        echo $target $local_release_dir $addons_branch;

        svn co http://code.sixapart.com/svn/movabletype/branches/release-$target /Sites/_live/cgi/release-$local_release_dir;
        echo SUCCESS: release-$target checked out;

        cd /Sites/_live/cgi/release-$local_release_dir;
        make;
        echo SUCCESS: make;

        mkdir /Sites/_live/html/r$local_release_dir;
        echo SUCCESS: created /Sites/_live/html/r$local_release_dir;

        chmod 777 /Sites/_live/html/r$local_release_dir;
        echo SUCCESS: permissions updated /Sites/_live/html/r$local_release_dir;

        cd /Sites/_live/html/r$local_release_dir;
        ln -s /Sites/_live/cgi/release-$local_release_dir/mt-static /Sites/_live/html/r$local_release_dir/mt-static;
        echo SUCCESS: symlink to /Sites/_live/html/r$local_release_dir/mt-static;

        chmod -R 777 /Sites/_live/cgi/release-$local_release_dir/mt-static/support;
        echo SUCCESS: permissions updated /Sites/_live/cgi/release-$local_release_dir/mt-static/support;

        cd /Sites/_live/cgi/release-$local_release_dir/;
        svn co http://svn.sixapart.com/repos/eng/mtaddons/branches/$addons_branch/addons/;
        echo SUCCESS: svn co $addons_branch/addons;

        svn co http://svn.sixapart.com/repos/eng/mtaddons/branches/$addons_branch/mt-static/addons mt-static/addons;
        echo SUCCESS: svn co $addons_branch/mt-static/addons;

        svn co http://svn.sixapart.com/repos/eng/mtaddons/branches/$addons_branch/mt-static/themes/tristan-blue mt-static/themes/tristan-blue;
        echo SUCCESS: svn co $addons_branch/mt-static/themes/tristan-blue;

        curl http://svn.sixapart.com/repos/eng/mtaddons/branches/$addons_branch/mt-cp.cgi > mt-cp.cgi;
        echo SUCCESS: svn co $addons_branch/mt-cp.cgi;

        chmod 755 mt-cp.cgi
        echo SUCCESS: chmod 755 mt-cp.cgi;

        mt_config="# Config File Generated via makemt command
CGIPath /cgi-bin/release-$target/
StaticWebPath /r$target/mt-static

ObjectDriver DBI::mysql
Database mt_r21
DBUser root
DBPassword root
DBHost localhost
#DBSocket /Applications/MAMP/tmp/mysql/mysql.sock

##### CGI LOCATIONS #####
# AdminScript mt.fcgi
# CommentScript mt-comments.fcgi
# TrackbackScript mt-tb.fcgi
# ActivityFeedScript mt-feed.fcgi
# XMLRPCScript mt-xmlrpc.fcgi
# AtomScript mt-atom.fcgi
# UpgradeScript mt-upgrade.fcgi

DebugMode 1
DeleteFilesAtRebuild 1
# HTTPTimeout 60
# EnableAddressBook 1
# ShowIPInformation 1";
        echo "$mt_config" > mt-config.cgi;
        echo SUCCESS: mt-config.cgi created;

        mate /Sites/_live/cgi/release-$local_release_dir/;
        mate /Sites/_live/cgi/release-$local_release_dir/mt-config.cgi;
    else
        echo 'usage = makemt target local_release_dir addons_branch';
    fi
}

Getting FastCGI configured and running can be a pain. There are FastCGI instructions on MovableType.org, but the page is so long that it looks kinda daunting.

Strangecode has got FastCGI enabled for all hosting accounts. So after installing Movable Type all I had to do to was the following two steps:

  1. Create symlinks to the primary MT scripts with names ending in .fcgi.

    $ cd /PATH/TO/MT
    $ for F in mt{,-comments,-search}.cgi; do ln -s $F $(basename $F .cgi).fcgi; done
    
  2. Add these lines to mt-config.cgi.

    AdminScript mt.fcgi
    CommentScript mt-comments.fcgi
    SearchScript mt-search.fcgi
    

Follow these steps to easily switch between versions of Movable Type.

Requirements

  • Subversion - Movable Type development is kept in a version control system called Subversion. Subversion allow many developers to work on the same code at the same time.
  • shell access - I use Terminal.app on my MacBook Pro.

Development Branches

There is a branch for each development cycle. These branches are worked on for 1-3 weeks, before a branch is closed and passed to QA for testing. If QA finds any bugs, then bugs are fixed in the branch. All subsequent features are implemented in the next branch sequentially. The branch with the highest number is the most current release (as of this writing, release-35)

Stable Tags

Once a particular place in development is tested and approved for release the code at that point is tagged with a release number.

Checkout the Code

These steps will be a little different based upon the setup of the web hosting environment. Here’s a simplified example of how I set-up Movable Type:

www.beausmith.com/
    cgi/
        release-33/
        release-34/
        mt  -> release-34
        mt4.01
        mt4.11
    html/
        blog/
            (archives here)
        index.php
        mt-static -> ../../cgi/mt/mt-static

The items with the arrow -> are symlinks. These allow me to not have to change urls when I update to a new release and also allow me to keep my mt-static directory inside the release folder. When I want to update to release-35, here’s the steps I’ll take:

  1. Navigate to the cgi directory & use the subversion checkout command to get the latest version:

    $ pwd;
    /www.beausmith.com
    $ cd cgi;
    $ svn co http://code.sixapart.com/svn/movabletype/branches/release-35;
    
  2. Issue the make command to build the current release

    $ make;
    
  3. Make the support files writeable

    $ chmod -R 777 release-35/mt-static/support
    
  4. Remove the current symlink and create a new symlink to point to your release branch. I do this in the same step so as to avoid any potential downtime while switching.

    $ rm mt; ln -s release-35 mt;
    

That’s it! Go access you MT installation.

Updating

Since changes will be committed round the clock by the MT teams in San Francisco and Japan, you’ll want to update often to get the latest changes.

    $ cd cgi/release-35;
    $ svn up;
    $ make;

Doing a make is not necessary unless there are *.pre files that need to be rendered for the current language.

Note: If you make changes to the files in the MT code, they may conflict with the updated code. Look forward to a future article about Subversion basics.

Switching Between Movable Type Installs

Is there a bug in release-35 and you want to go back to the stable mt4.11 install? Easy. Remove the mt symlink and then create a new one pointing to the desired MT install:

    $ rm mt; ln -s mt4.11 mt;

View Changes & Code Diffs with Trac

Trac also makes it easy to browse through all the recent changes to any branch of Movable Type. Note the similarity & differences in the urls

  • trac: http://code.sixapart.com/trac/movabletype/browser/branches/release-35/
  • svn: http://code.sixapart.com/svn/movabletype/branches/release-35/

Questions? Please comment below.

The first three lines of this entry’s content is:

<style type="text/css">
#entry-55 ul li { color: blue; }
</style>

Are the items in this unordered list blue?

  • blue
  • blue
  • blue

If so, I’ve added custom styles to this single entry.

  1. Create your entry
  2. Save it as draft
  3. Look in the url of your browser to find the id which is a unique identifier for the entry (careful not to use blog_id as that is a unique id for the blog)

    http://www.chezbeau.com/cgi-bin/mt/mt.cgi?__mode=view&_type=entry&id=55&blog_id=2&saved_changes=1
    
  4. Enter the id into your css

  5. Change Status to Published
  6. Save your entry

All this assumes you are using the default templates from MT, if not you’ll have to add <$mt:EntryID$> to a container wrapping each entry in your templates.

By default, assets are placed in the site root as defined in the publishing settings. For example, if the site root was http://beausmith.com/ then the asset image.gif would be uploaded to http://beausmith.com/image.gif.

There are two common ways to change this: 1. Define a default upload destination folder. 2. Hard code upload destination and hide it from the form.

1. Define a default upload destination folder

To pre-populate the folder where assets will be placed add this line to the top of MT_BASE/tmpl/cms/include/asset_upload.tmpl and replace “assets” with your preferred folder name:

<$mt:setvar name="extra_path" value="assets"$>

I use “assets” because this is the most generic word to describe all the things that could be placed in this folder: photos, video, documents etc.

2. Hard code upload destination and hide it from the form

Open MT_BASE/tmpl/cms/include/asset_upload.tmpl and search for this code (from MT4.0, code from MT4.1.x has a big chunk of javascript in the middle of the second <mtapp:setting> block, but the javascript can safely be removed as well):

<mt:setvarblock name="upload_hint">
    <__trans phrase="_USAGE_UPLOAD" params="<$mt:var name="blog_name" escape="html"$>">
</mt:setvarblock>
<mtapp:setting
    id="folder"
    label_class="top-label"
    label="<__trans phrase="Upload Destination">"
    hint="<$mt:var name="upload_hint"$>"
    show_hint="1">
    <!-- <$mt:var name="blog_url" escape="html"$> -->
    <select name="site_path" onchange="setExtraPath(this)">
        <option value="1">&#60;<__trans phrase="Site Root">&#62;</option>
    <mt:if name="enable_archive_paths">
        <option value="0"<mt:if name="archive_path"> selected="selected"</mt:if>>&#60;<__trans phrase="Archive Root">&#62;</option>
    </mt:if>
    <mt:if name="extra_paths">
        <mt:loop name="extra_paths">
        <option value="<mt:if name="enable_archive_paths">0<mt:else>1</mt:if>" middle_path="<mt:var name="path" escape="html">"<mt:if name="selected"> selected="selected"</mt:if>><mt:var name="label" escape="html"></option>
        </mt:loop>
    </mt:if>
    </select>
    / <input name="extra_path" id="extra_path" value="<mt:var name="extra_path" escape="html">" />
</mtapp:setting>

Replace the code with this code which will set the upload destination to <Site Root>/assets/:

<input type="hidden" name="site_path" id="site_path" value="1" />
<input type="hidden" name="extra_path" id="extra_path" value="assets" />

The “Upload Destination” form elements should now be gone from the upload asset modal.

Note: There are other ways to do this in the Perl code. It’d be nice to just have config directives to handle this.

I was adding more examples to the Movable Type Documentation site today and my lines of code were so long that they went beyond the width of the column… so I implemented some css to use a scrollbar to display longer lines. Shorter lines display without the scrollbar.

Examples (and HTML source)

Short code renders no scroll bar…

<pre><code>short code example</code></pre>

Long code renders scroll bar…

<pre><code>long code example (is it odd that the word "short" is longer that the word "long") long code example long code example</code></pre>

CSS Code

pre {
    overflow: auto;
    width: auto;
    background-color: #f0f6fa;
    border: 1px solid #CCCCCC;
    border-width: 1px 0;
    padding: 10px;
}
  • overflow: auto; - creates the scrollbar if content is wider than container.
  • `width: auto; - .
  • <pre> “preformatted” — all the spaces and carriage returns are rendered exactly as you type them. All other formating (links, code, etc) are preserved.
  • <code> tag renders in mono-spaced font.
  1. login to mysql

    $ mysql -u USERNAME -p DATABASENAME
    
  2. find id of user

    > select author_name, author_id from mt_author;
    +---------------+-----------+
    | author_name   | author_id |
    +---------------+-----------+
    | beau          |         1 |
    | quinn         |         2 |
    | ryan          |         3 |
    | jono          |         4 |
    +---------------+-----------+
    
  3. issue the command using the correct author id from the table

    > update mt_author set author_is_superuser = 1 where author_id = 1;
    

About this Archive

This page is an archive of recent entries in the Tips & Tricks category.

code is the previous category.

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

OpenID accepted here Learn more about OpenID
Powered by Movable Type 4.21-en