Help - Search - Members - Calendar
Full Version: Server side includes and rebuilding
Movable Type Community Forum > Additional Resources > Tips and Tricks
NotAbbott
Okay, I've looked around a bit for this, and haven't been able to find it, or at least find it articulated the same way I've got it in my head.

I want to have a "5 most recent posts" side bar down at the individual entry/archive level on my site. Except that I want "recent" to be "now," not when the page was written.

At the main page level, this is somewhat trivial, because the index page gets rebuilt whenever there's a new entry. I guess my question is sort of a fundamental SSI question: When does the content get "included"? Only when MT writes the page, or is it truly dynamic, in that it shows up when the user loads the page?

I'm pretty sure it's the former, and that I may have to rethink this design strategy, but I wanted to make sure. It's not that big a deal for users to have to click to the index page for each section to see the latest posts.

The site is www.notabbott.com -- be gentle, it's got a lot of structural and design issues.

Later,
COZ
NotAbbott
While I'm at it, what's the root URL that the standard "<!--#include virtual="/directory/filename.inc" -->" refers to? Is it the path or the URL from the config settings? I just tweaked the site so my upcoming gigs would show up as an include on the front page, but the same code on the music page (which has the same path -- all the filenames have the directory built in -- but a different URL -- with the directory name in it so "view site" works properly) doesn't work. I tried backing it out (../directory/filename.inc), but that didn't work, either.

The two pages in question are the main notabbott.com page and the "music" main page.

Thanks in advance.

Later,
COZ
NotAbbott
Okay, scratch that second post. Hadn't switched the music main page to shtml.
jblayloc
I use server-side includes to keep updated lists of entries on my category and individual archive pages.

Step 1. Create a new index template. I call mine "Recent Entries." It uses the following code:

CODE
<div class="side">
<b>Recent Entries:</b><br>
<MTEntries lastn="15">
<a href="<$MTEntryPermalink$>"><$MTEntryTitle$></a><br />
</MTEntries>
</div>


This produces a list of the 15 most recent entries, so you'd want to change it to 5.

Step 2. Before saving your new index template, specify an output file. This is the filename for the list of entries, and it's the file you'll be including in the individual entry archive template. I call mine "recent.html" and it goes in a folder called "includes."

Step 3. Make sure the box next to "Rebuild this template automatically when rebuilding index templates" is checked, and then save and rebuild your index templates. Now you can check to see if it worked by typing recent.html into your browser. (Here's mine to give you a sense of what it looks like.)

Step 4. In your individual entry archive template, include the file. I use SSI, so my individual entry archive pages all end in .shtml and contain the following:

CODE
<!--#include virtual="../includes/recent.html"-->


You could also do it using PHP if you wanted to. I use SSI.

Step 5. Save your individual entry archive template and rebuild. You should see a list of recent entries, with links to them, in your individual entry pages.
NotAbbott
What's odd is that's what I had been doing, but for some reason, I didn't think it was updating. With your description in tow, I tested it a bit more thoroughly, and yeah, that does work exactly as promised.

Thanks.

Now I just have to convert my whole site to shtml, but I have to propogate some design changes anyway.

Later,
COZ
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.