Sillybean

April 22, 2004

List of next three events from Movable Type calendars

This morning I needed a way to get the next three upcoming events from the HSC Calendar listed on the home page. Here’s how I got it to work.

I already had the calendar set up with some PHP to filter out events that happened before today (notes on how this was done). What I needed was a way to get a limited number of entries starting at that point.

Here’s the code to get the list of all future entries in a format we can include in some other page. The event title is linked to more information, and the date is printed after that, enclosed in a span with class ”date” so we can format it however we like.




    $now=date("Ymd");
    $entry=date("<$MTEntryDate format="%Y%m%d"$>");
    if ($now<=$entry) {
    ?>

  • <a href="<$MTEntryPermalink$>"><$MTEntryTitle$> <$MTEntryDate format="%B %e"$>


A simple loop gets us only the next three events. Create a new index template (”Upcoming events”) and make sure the filename as a .php extension. Paste this in (code added from the previous version is in bold):





    $now=date("Ymd");
    $entry=date("<$MTEntryDate format="%Y%m%d"$>");
    if (($now<=$entry) && ($i<3)) {
    ?>

  • <a href="<$MTEntryPermalink$>"><$MTEntryTitle$> <$MTEntryDate format="%B %e"$>

  • $i++; ?>


You can see the loop counter being initialized and incremented, but where’s the loop? It’s the MTEntries tag. Movable Type loops through the code inside those tags already; no need to add a PHP loop on top of that. Just change $i<3 to suit the number of events you need in your list, and include this file elsewhere in your site.

No comments yet.

Sorry, the comment form is closed at this time.

'round here

Writing & Publishing 101

Paged Media: Web Design for Authors

elsewhere

iPhoto ‘09 and Domain Language — Nice bit on how software (and web) interfaces are about language, and how Apple is changing the photo software field by moving past the standard photo album metaphor.

Comment on this

OH CANADA NO. (further discussion, supplemented by entertaining computer engineering metaphors, over at Making Light)

Comment on this

Thank You for Choosing the Hyatt Regency Purgatory “An automatic-teller machine is located in the lobby. For your convenience, it is attended at all hours and in perpetuity by the bank executive who came up with the idea of ATM fees.”

Comment on this

Twilight in Fifteen Minutes — Scathing and brilliant.

Comment on this

The Minority Report hand-waving computer interface is now real. Its users will have the best toned arms in the office.

Comment on this

The Matrix runs on Windows. Ow. It hurts to laugh that hard.

Comment on this

Google flu trends — doing something useful with all those searches for “flu symptoms.”

Comment on this

I’m addicted to the NYTimes maps this morning, especially the county bubble view. Hello, population distribution! It’s fascinating to compare this year to 2004.

Comment on this