MT: Extended Entries

In Movable Type, extended entries are used to provide flexibility in the display of a post. The best example is hiding a portion of a very long post. This remainder of this post (the extended part!) explains how to configure MT templates to employ extended entries that expand and collapse the text on the index page itself instead of moving to the individual post page.

When I was developing my MT templates, I was not concerned at all about the extended entry part of the template. This was because I had already decided that I was never going to use it anyways. My logic was assuming that most people would not bother to click to read the rest of the post. I was also not satisfied with the way the extended link worked. In the standard template, it takes the user away from the index page and to the individual post. This is disruptive when the user is trying to catch up on all latest posts.

I changed my mind for two reasons. First, I often write long posts and understand that every post will not interest every reader. I would rather have a reader skim the first two paragraphs of several posts and end up spending more time here then have him get bogged down in a very long post and quit the site. Second, I have noticed that many sites have extended entries which expand and collapse instantly, without leaving the page. There are many sites that do this, but first place I noticed it was at Winds of Change.

Before I explain how to modify your template to do this, I have to give credit where credit is due. The javascript is from the amazingly useful Scriptygoddess, more specifically in this post. I'm just trying to provide a very clear installation explaination for it (plus one additional step which was not mentioned there).

Implementing expandable extended posts into your index template involves three simple steps:

Step 1: Adding the Javascript

In your index template, the following script needs to be inserted above the </head> tag:
<script language="javascript">
function showMore(varA1, varB1){
  var123 = ('varXYZ' + (varA1));
  varABC = ('varP' + (varA1));
  if( document.getElementById ) {
    if( document.getElementById(var123).style.display ) {
      if( varB1 != 0 ) {
        document.getElementById(var123).style.display = "block";
        document.getElementById(varABC).style.display = "none";
      } else {
        document.getElementById(var123).style.display = "none"; 
        document.getElementById(varABC).style.display = "block";
      }
    } else {
      location.href = varB1;
      return true;
    }
  } else {
    location.href = varB1;
    return true;
  }
}
</script>

Step 2: Modifying the Extended Display Section

Find the <$MTEntries$> tag in the template. At some point below that there should be something similar to:
<MTEntryIfExtended>
  <span class="extended">
  <a href="<$MTEntryPermalink$>#more">
  Continue reading "<$MTEntryTitle$>"
  </a></span><br />

</MTEntryIfExtended>
Replace everything between (and including) the <MTEntryIfExtended> tag and the </MTEntryIfExtended> tag with the following:
<!-- ENTRY EXTENDED BODY -->
<MTEntryIfExtended>
  <span id="varP<$MTEntryID$>">
    <p><a href="#<$MTEntryID pad="1"$>"
    onclick="showMore(<$MTEntryID$>,'<$MTEntryLink$>#<$MTEntryID pad="1"$>');
    return false;">Show me the rest</p></a><br />
  </span>
  <div id="varXYZ<$MTEntryID$>" style="display: none">
  <p><$MTEntryMore$></p>
    <p><a href="#<$MTEntryID pad="1"$>"
    onclick="showMore(<$MTEntryID$>,0);return true;">
    Ok, I've seen enough</p></a>
  </div>

</MTEntryIfExtended>
At this point, the expand/collapse extended works wonderfully except for one remaining issue. When you collapse, the text collapses but the window does not scroll back to the post that was just collapsed. If the extended section is long, the user may be left several posts down from where they started. Actually, the code is attempting to jump back to the current post, but if there is no anchor to jump to, it ends up just staying in the same location. This took me a little time to figure out but the solution is very simple.

Step 3: Add an Anchor to the Start of Each Post

Find the <$MTEntryTitle$> tag. Immediately prior to this tag, add the following line:
<a name="<$MTEntryID pad="1"$>"></a>

It is important to note that although the extended portion is hidden from view, that portion of the post is still loaded just the same as if it were visible. Therefore, placing images in the extended section to make the index more efficient will not work if you use this method of showing extended text. Of course, the bright side is the search engines will find the extended text on the index page instead of just on the individual post pages.

UPDATE: If you are using the BASE tag to set the default target to "_blank" (forcing all links to open in a new window), the collapse link anchor must also have the following:

target="_self"
If you do not have this explicitly defined, then pressing the collapse button will also open a new window which is definitely not what we are trying to accomplish here.

Trackbacks
The trackback URL for this entry is:
http://king-of-fools.com/blog/trackback/173/Uk04mmHZ/
  1. Extended Entries
    I've been looking all over for the code that makes extended MT entries sort of open and close within the page (like on Nicole Lee's blog, where I first noticed it). I finally found the way to do it here....
    Tracked by: : Lodenocity.com on 05/30/2004 at 6:45 pm
  2. Expand/Collapse Entry Body Test
    This is a test to see if my recent addition of the javascript I found here will work to expand and collapse a long entry without the reader leaving the page....
    Tracked by: : the day lee misadventures on 01/13/2004 at 1:10 am
Comments

Thanks. The expanded entry function seems to be working.

Posted by: zenwanderer - 07:49 AM - 01/16

Hey big thanks for this useful mod!

Posted by: y - 03:42 PM - 04/02

Most excellent King. This code rules.

abm

Posted by: angrybrownman - 07:56 PM - 05/22

Glad you found it helpful!

Posted by: King of Fools - 10:08 AM - 05/23

I agree, great stuff, thanks!

Posted by: charlespence - 08:11 AM - 08/26

Hey brilliant idea but one question… I am at a lost to find out how to tell it turn on or better put how many words or lines to cut off the text and have the link. help please

Posted by: - 12:54 AM - 11/23

It is not automatic.  You divide your post into the body and extended sections and then the body part appears with the extended part hidden. 

Alternatively, you could modify the template so that it used the excerpt instead of the body and then when you pressed the more arrow, it would hide the excerpt and display the body section (which contained the entire post).  In MT you can configure the number of words in your excerpt section.

Posted by: - 12:38 PM - 11/24
Post Your Comment
Commenting is not available in this weblog entry.
Categories
Archives
September 2010
S M T W T F S
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    

Complete Archives

Tools
Search:
  Advanced Search

Mailing List:



Currently Reading
Recently Read
Animal Farm

Animal Farm
George Orwell

Life of Pi

Life of Pi
Yann Martel

The Fourth K

The Fourth K
Mario Puzo

Catch 22

Catch 22
Joseph Heller

the Sicilian

the Sicilian
Mario Puzo

The Quantum Rose

The Quantum Rose
Catherine Asaro

Members
Sponsors
Blogroll
Links
Stats
Entries: 2147
Comments: 2925
Trackbacks: 665
Members: 258

Most Recent:
  Entry: 11/09/08 9:38
  Comment: 11/17/08 12:27
  Visitor: 09/09/10 12:30

Powered by:
  ExpressionEngine

Extreme Tracking