October 18, 2003

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.

Categories
Archives
March 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 31      

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: 03/13/10 11:34

Powered by:
  ExpressionEngine

Extreme Tracking