Help - Search - Members - Calendar
Full Version: An excellent solution?
Movable Type Community Forum > Additional Resources > Tips and Tricks
robbear7
My MT has accumulated 170 entries this month. This is great, except I have a side bar on all pages with the 5 most recent entries. The only problem was the older posts were not being updated with MT.. which is understandable. Submitting an entry would be hard on system resources and would take ages to build 170+ pages.

I had to find a way to include the recent entries on all pages without the use of SSI nor PHP.. simply because I refuse to give up my extension of .htm .

Well, I found a solution that seems to work great, but it is so easy of a solution that I'm sure there is a draw back I havent thought of yet.

I created a new index page for each category that is actually a javascript. I named the new index page with a .js extension. The javascript looks like this:
CODE
// Processes the recently posted entires. This method is used to dynamically display  
// Movabletype recent entries on all pages without the need of server side includes or PHP.
// Category: IN THE NEWS
document.write('<ul>');
<MTEntries category="In the news" lastn="5">
document.write('<li><a href="<$MTEntryPermalink$>"><$MTEntryTitle$></a></li>');
</MTEntries>
document.write('</ul>');
//

Then in my sidebar I included the javascript using simply:
CODE
<script language="JavaScript1.2" src="http://www.generation77.com/inthenews.js" type="text/javascript"></script>

It works fantastic, as long as I keep single quotes and other expressions out of the Entry titles. It seems to work great on all browsers I've tested with.

Is there any drawbacks to this method that I havent thought of?
deker
If someone has turned javascript off in their browser, it won't show up. And if they look at it with a cellphone, pda, or text based browser it probably won't show up.

Why do you refuse to give up the .htm extension? Doing it with PHP or SSI would ensure it worked for everyone, regardless of platform.
robbear7
Thanks Deker, I have taken into thought that those without Javascript will not beable to view the recent entries. I'm still debating over that issue.

I don't have PHP available to me, so that is why PHP is out of the question. At this point, Google has indexed all my pages, and switching to SHTML would delay things and cause an amount of confusion for the next couple of weeks.. or even a month with search results.

I dunno, I've had some real bad experiences with SSI in the past.. I tend to avoid it as much as possible. But that's just my personal experience.
girlie
QUOTE (robbear7 @ Aug 30 2003, 02:18 PM)
It works fantastic, as long as I keep single quotes and other expressions out of the Entry titles.


You can use:

CODE
<MTEntryTitle encode_js="1">


QUOTE
encode_js
When set to 1, encodes the tag value into a format suitable for usage in a Javascript string value. For example, if the value of the tag without this attribute were Foo "Bar" Baz's 1/2 Quux, the encoded version would be Foo \"Bar\" Baz\'s 1\/2 Quux.
robbear7
Wow! Thanks girlie. I would have sought after documentation if I had even thought such an attribute existed, but..wow.. I just had no idea.

I have noticed however that it does not encode it as the documentation indicates it would. It worked great with the title:
QUOTE
Kazaa most 'scanned' in RIAA subpoena war

and converted it as so:
QUOTE
Kazaa most \'scanned\' in RIAA subpoena war

But this title:
QUOTE
RIAA Discovers MD5/Yet to Discover Critical Thinking
is left untouched. According to the documentation, the foward slash is encoded with the backslash
QUOTE
1/2 Quux

QUOTE
1\/2 Quux

I had set the permalink to be encoded as well.. but same thing.. backslashes are ignored. All works well regardless, but I'm just a bit confused. Is this an error in the documentation or what am I missing?

Below is my js source.. and below that is the output:
CODE
// Category: IN THE NEWS
document.write('<ul>');
<MTEntries category="In the news" lastn="5">
document.write('<li><a href=\"<$MTEntryPermalink encode_js="1"$>\"><$MTEntryTitle encode_js="1"$></a></li>');
</MTEntries>
document.write('</ul>');
//

CODE
// Category: IN THE NEWS
document.write('<ul>');
document.write('<li><a href=\"http://www.generation77.com/entry/in_the_news/000174.htm\">Civil Disobedience, p2p</a></li>');
document.write('<li><a href=\"http://www.generation77.com/entry/in_the_news/000173.htm\">RIAA Discovers MD5/Yet to Discover Critical Thinking</a></li>');
document.write('<li><a href=\"http://www.generation77.com/entry/in_the_news/000172.htm\">Kazaa most \'scanned\' in RIAA subpoena war</a></li>');
document.write('<li><a href=\"http://www.generation77.com/entry/in_the_news/000171.htm\">Learning to Live with Legal Music Services</a></li>');
document.write('<li><a href=\"http://www.generation77.com/entry/in_the_news/000170.htm\">Campuses fight internet piracy</a></li>');

document.write('</ul>');
//
stepan
QUOTE (robbear7 @ Aug 30 2003, 02:18 PM)
Is there any drawbacks to this method that I havent thought of?

Beside the stuff others mentioned, the problem with using Javascript includes is that it slows the page loading a little (the browser has to make an extra request for the included file) but that shouldn't be too noticible. Also, I'd be afraid that browsers might cache the .js file and you wouldn't see the most up-to-date info. But maybe they're smarter than that smile.gif

As far as wanting to stick to .htm extensions, you might be able to do that and still use PHP or SSI. On many (most?) hosting accounts, you can tell the server how to treat file extensions. For example, putting the following line into your .htaccess file will process .htm files as SSI documents:
CODE
AddType text/x-server-parsed-html .htm

Here is some more info on this.
robbear7
thanks for the excellent suggestion stepan. However, upon uploading the modified .htaccess I started receiving "Internal Server Errors" while trying to open mt.cgi, well any .cgi file for that matter. Upon removing the .htaccess modification, all was well again.

I'll have to take this up with my hosting provider.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.