| |||||||||||||||||||||||||||||||||||||||||||||||||
One of the main conventions of blogging is the presentation of content in reverse-chronological order. When a reader visits a blog, she is inevitably presented with the most recent entry at the top of the page, with a series of older entries available as she scrolls down.
This works great for blogs composed primarily of links, or for news-oriented sites that need to keep the freshest info front-and-center. But blogs encompass more territory than news and links.
For example, what about an online diary? A life described in reverse might be an interesting literary device, but it's probably going to be more confusing than anything. And what if your blog is used to tell a serialized story? Beginning at the beginning often makes for a better reading experience, right?
Well, here is the info you need to make your JournURL-powered blog take these issues into account. All you really need is to leverage the <weblog:variable> tag in your blog's index template.
Here's the blog-related bit of a sample template:
<weblog:entries> <h1><weblog:subject></h1> <p><weblog;body></p> </weblog:entries>If you were to apply such a template to your blog, you'd end up with your index page displaying something like this:
Entry #3
This is the text of entry 3Entry #2
This is the text of entry 2Entry #1
This is the text of entry 1So how do we reverse that? It's pretty simple, with a little imagination and understanding of JTML.
<weblog:variable name="content"></weblog:variable> <weblog:entries> <weblog:variable name="content"> <h1><weblog:subject></h1> <p><weblog;body></p> $content$ </weblog:variable> </weblog:entries> $content$Run that template through your blog and the result will be:
Entry #1
This is the text of entry 1Entry #2
This is the text of entry 2Entry #3
This is the text of entry 3So how does the second version work its magic? If you're non-technical, don't worry about it. Just trust that it does work. But if you're curious...
- We establish a variable called "content" and set it to an empty string.
- Inside the <weblog:entries> loop, we once again define a variable called "content", which will overwrite the one we defined previously. But not before...
- ...we display the existing value of "content" within the variable definition itself. See the "$content$" right before </weblog:entries>? When your template finds a word wrapped in dollar signs, it assumes you're trying to display the value assigned to a variable of the same name.
- At the end of the entry loop, we once again tell our template to display the value of $content$.
So why does this work? On the first pass through the loop, "content" is set to nothing, and thus displays nothing. On the second pass, it contains the newest entry in your blog, and tacks it on to the end of the next one in line.
This process repeats through all the entries on the page, building a "content" variable that always has the oldest entry at the top. When the loop is done and we display "content" one last time, we end up with a chronologically sorted list of entries.
Other discussions along these lines:
03-30-2004 10:56:39AM - Permalink - Post Reply - Read Comments [0] category: Tutorials and Tips
related topics: (blogging) (reverse chronological order)