Hacking Movable Type to Create and Integrate Advertising Posts

A few people asked me how to customize MovableType to add advertising posts on the individual archives, category pages, and main pages in MovableType powered blogs.

MovableType is fairly easy to customize, but you have to customize the different templates differently. I have been a bit slow to getting around to doing this, so sorry on that.

Opening Tips:

  • The day I changed the format of my blog to include the advertising post inline my income tripled. That is a huge deal if you participate in keyword markets where you pay per click. It may make many keywords that were once prohibitively expensive become affordable.

  • If you are unsure how to do something ask at the MovableType forums.
  • If you are changing a template make a file called something like templatename-old and save a copy of the old template before making any changes.
  • Each template that you want to change will require customizations.
  • My template is a bit hacked up from a normal install, so the code to change your layout 1 for 1, but this post aims to show the general idea of how to change your templates.
  • I do not sell MT customization services. I can offer general ideas, but I am not a template or code expert on any level.

Customizing the main page:

 

The MovableType templating system has a couple important features that make this easy to do. The three big things you need to know are:

  • lastn - how many posts you want to feature in that segment

  • including your post - easy enough, eh
  • offset - how many of the most recent posts to skip before you start posting the next set of posts

So you start your blog and you have your container and whatnot. The first thing you need to decide is how many posts you want to show above your advert. Currently I show 1.

So you start your content area, and after the div id=content you enter
<MTEntries lastn="1">

So my home page content container area starts with

<div id="container">

<div id="content">

<MTEntries lastn="1">

<$MTEntryTrackbackData$>



<div class="post">

<a name="<$MTEntryID pad="1"$>"></a>

<h2><$MTEntryTitle$></h2>

<MTDateHeader><div class="date"><$MTEntryDate format="%b"$><br /><$MTEntryDate format="%e"$></div></MTDateHeader>



<div class="entry">

<$MTEntryBody$>



<MTEntryIfExtended>

<p><a href="<$MTEntryPermalink$>#more">Continue reading "<$MTEntryTitle$>"</a></p>

</MTEntryIfExtended>

</div>



<div class="post_meta_left">

<p class="categories">Posted in: <MTEntryCategories glue=" "><a href="<$MTCategoryArchiveLink$>"><$MTCategoryLabel$></a></MTEntryCategories></p>

<p class="post_author">by <a href="http://www.seobook.com/about.shtml">Aaron Wall</a></p>

</div>

<div class="post_meta_right">

<MTEntryIfAllowComments>

<p class="thoughts"><a href="<$MTEntryPermalink$>#start_comments">Your Thoughts?</a> [ <$MTEntryCommentCount$> ]</p>

</MTEntryIfAllowComments>

<p class="perma"><a href="<$MTEntryPermalink$>"><$MTEntryDate format="%x"$></a></p>

</div>

</div>



</MTEntries>

If you wanted 2 posts above the advert post the above would be lastn=2.

 

Advertisement or Offer Post:

 

After you create your first post you can include the advert post. I recommend creating a mini post instead of placing a huge advertisement. I probably would do better if I had an autoresponder series in a small advert post rather than my current ebook one.

To input your advertisement post you can create a backdated post and then just include that in the templating system. My post 142 is my advert post. So for me the code looks like this

<MTEntry id="142">

<div class="post">

<h2><$MTEntryTitle$></h2>

<div class="entry">

<$MTEntryBody$>

</div>

</div>

</MTEntry>

 

Remainder of Home Page:

 

After the advertisement it is time to publish the rest of the page content. So now you need to use lastn again, but this time you have to offset it. So you use code that looks something like

<MTEntries lastn="10" offset="1">

<$MTEntryTrackbackData$>



<div class="post">

<a name="<$MTEntryID pad="1"$>"></a>

<h2><$MTEntryTitle$></h2>

<MTDateHeader><div class="date"><$MTEntryDate format="%b"$><br /><$MTEntryDate format="%e"$></div></MTDateHeader>



<div class="entry">

<$MTEntryBody$>



<MTEntryIfExtended>

<p><a href="<$MTEntryPermalink$>#more">Continue reading "<$MTEntryTitle$>"</a></p>

</MTEntryIfExtended>

</div>



<div class="post_meta_left">

<p class="categories">Posted in: <MTEntryCategories glue=" "><a href="<$MTCategoryArchiveLink$>"><$MTCategoryLabel$></a></MTEntryCategories></p>

<p class="post_author">by <a href="http://www.seobook.com/about.shtml">Aaron Wall</a></p>

</div>

<div class="post_meta_right">

<MTEntryIfAllowComments>

<p class="thoughts"><a href="<$MTEntryPermalink$>#start_comments">Your Thoughts?</a> [ <$MTEntryCommentCount$> ]</p>

</MTEntryIfAllowComments>

<p class="perma"><a href="<$MTEntryPermalink$>"><$MTEntryDate format="%x"$></a></p>

</div>

</div>



</MTEntries>

</div>

 

Individual Entry Pages:

 

I simply hard coded the ad text into the template on individual entry pages. After the post and comments section were closed I added this:

<div class="post">

<h2><!--#config timefmt="%B %d, %Y" --> <!--#echo var="DATE_LOCAL" --></h2>



<div class="entry">



<p>Ad entry text</p>

</div>

</div>

 

Server Side Includes:

 

Notice how that date of my advert uses what looks like a comment. That is actually a server side include that is used to parse the date from the local machine as being the current date. Useful to do to make your content look fresh if you are using freshness as a sales point for your software, information product, or other offer.

If you are having your site created dynamically I think you could insert that information using a php date command.

Also note that I stress the date instead of an offer. For most people the date is probably not so important, and they could probably put their post title or whatever in the H2 tag or whatever type of post heading they were using for other posts.

If you are outputting to static html files by default your server will not process server side include directives. You can set your file extensions to .shtml inside the MovableType settings, but doing that would cause you to lose whatever link equity you have built up from pages located at the old locations.

Instead, you can configure your .htaccess file so that your site processes .html or .htm files as though they were .shtml. Your .htaccess file is simply named .htaccess and exists in the root of your site. Please note that some FTP programs do not show .htaccess files, so you may want to ask your host if you have one if you can't find it.

Please note that I do not recommend screwing with your .htaccess file on an important site without supervision, as a poorly configured one can cause a site to not load at all. I have temporarily screwed up a number of my sites playing with them...but you have to learn somehow. Also, make a copy of your htaccess file before screwing with it.

Also be aware that you may already have a .htaccess file that you do not want to write over. Instead download it to your local machine. After you download the file change it from .htaccess to htaccess.txt. After whatever code is already in it you can add

AddType text/html .shtml
AddHandler server-parsed .htm
AddHandler server-parsed .html
AddHandler server-parsed .shtml

Save that file. Then change it from htaccess.txt to .htaccess and upload it to the server in the root of your site.

 

Date or Category Archives:

 

Here I just inserted the post after the opening container and content area

<MTEntry id="142">

<div class="post">

<h2><!--#config timefmt="%B %d, %Y" --> <!--#echo var="DATE_LOCAL" --></h2>

<div class="entry">

<h2><$MTEntryTitle$></h2>

<$MTEntryBody$>

</div>

</div>

</MTEntry>

If you have further questions I probably can't answer them, but I hope that helps a few people.

Published: April 28, 2006 by Aaron Wall in blogs

Comments

April 29, 2006 - 11:23pm

Hi,

Great post.

I have MT myself for my .dk website and will definitely try your code on it.

Thank you for sharing it with us.

Regards,
Nikolaj

Add new comment

(If you're a human, don't change the following field)
Your first name.
(If you're a human, don't change the following field)
Your first name.
(If you're a human, don't change the following field)
Your first name.