Stephanie Leary

Writer and WordPress consultant

  • Books
    • Content Strategy for WordPress (2015)
    • WordPress for Web Developers (2013)
    • Beginning WordPress 3 (2010)
  • Blog
    • Fascism Watch (2016-17)
    • Content Modeling for WordPress series
    • WordPress Hidden Gems series
  • Work
    • Portfolio
    • Services
    • WordPress Plugins
    • WordPress Themes
    • Presentations and Interviews
    • on GitHub →
  • About
    • Press Kit
  • Contact
    • Mailing List

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

Latest WordPress Book

Content Strategy for WordPress

A short book for content strategists and managers on implementing a complete content strategy in WordPress: evaluation, analysis, content modeling, editing and workflows, and long-term planning and maintenance.

Read the sample chapter

Kindle Nook iBooks Kobo Smashwords

WordPress for Web Developers

WordPress for Web Developers (9781430258667)

This is a book for professional web designers and developers who already know HTML and CSS, and want to learn to build sites with WordPress. The book begins with a detailed tour of the administration screens and settings, then digs into server-side topics like performance and security. The second half of the book is devoted to development: learning to build WordPress themes and plugins.

This is the second, much-revised and updated edition of Beginning WordPress 3, with a more accurate title. Everything’s been updated for WordPress 3.6.

WordPress for Web Developers is out now. See what's inside...

The best WordPress features you’ve never noticed

  • WordPress Hidden Gems: Screen Options
  • WordPress Hidden Gems: Bulk Edit
  • WordPress Hidden Gems: Private Status
  • WordPress Hidden Gems: Dashboard Feed Readers
  • WordPress Hidden Gems: Options.php

Content Modeling for WordPress series

  • Content modeling for WordPress, part 1: analyze content
  • Content modeling for WordPress, part 2: functional and organizational requirements
  • Content modeling for WordPress, part 3: a sample content model

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.

Copyright © 2022 Stephanie Leary