• Skip to primary navigation
  • Skip to main content
  • Skip to footer
  • Books
    • Content Strategy for WordPress (2015)
    • WordPress for Web Developers (2013)
    • Beginning WordPress 3 (2010)
  • Blog
    • Content Modeling for WordPress
    • WordPress Hidden Gems
    • Web Design
  • Work
    • Presentations and Interviews
    • on GitHub →
    • MLIS Class Projects (2019-2022)
    • Portfolio (2002-2019)
    • WordPress Plugins

Stephanie Leary

Writer, Front End Developer, former WordPress consultant

  • About
    • Press Kit
    • Presentations and Interviews
  • Contact Me

List of next three events from Movable Type calendars

April 22, 2004 Stephanie Leary

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.

Blogging

This is an excerpt from Content Strategy for WordPress.My latest books are Content Strategy for WordPress (2015) and WordPress for Web Developers (2013). Sign up to be notified when I have a new book for you.

Footer

My Books

I’m a front end developer at Equinox OLI, working on open source library software. I was previously a freelance WordPress developer in higher education. You can get in touch here or on LinkedIn.

Copyright © 2025 Stephanie Leary · Contact