PHPlugins: Time-boxing an exhibit

Consider this:

We’d like to set up a limited exhibit space on our website. Here, we’ll run time-boxed exhibits, with fixed opening and closing dates. We’d like PHPlugins to handle the scheduling.

In this tutorial, I’ll lay out how to get it done.

Create an album as you would any other. For now, enable the “Hide from Album Set” and “Hide from Search” options to make the album invisible.

For the album slug, I’m going to use “current-exhibit”. Use whatever name you like, but take note of the name being used in the code below.

Add some images, and a placeholder description.

In our PHPlugins file, let’s scaffold our functions.

Every album in Backlight has two distinct content areas, the copy and the album; PHPlugins addresses them separately. We want to toggle the display of both using the same conditions, and so we’ll bind their display to a common value.


private $isOnPublicDisplay = true;

function copy_top() {
  return $this->isOnPublicDisplay;
} // END /**/

function album_top() {
  return $this->isOnPublicDisplay;
} // END /**/

Now, the display of our album copy and album grid are bound to a common value. We can toggle the display of both, simply by updating the value of $isOnPublicDisplay.

Our examples will continue to use album_top, the PHPlugins hook for targeting albums specifically. If you need to target and album set instead, then simply swap this for albumset_top.

We want our logic to only affect our current-exhibit album, so we’ll make that a wrapping condition for all of our logic to come.


private $isOnPublicDisplay = true;

function copy_top() {
  if ($this->slug === strtoupper('current-exhibit')) {
    $this->isOnPublicDisplay = false;
  }

  return $this->isOnPublicDisplay;
} // END /**/

function album_top() {
	return $this->isOnPublicDisplay;
} // END /**/

With the current logic in place, all of our albums will now display as normal, except the current-exhibit album, which will display no content. It displays blank, because we’re setting $this->isOnPublicDisplay = false; specifically for that album.

And now you can probably see where we’re going. We’ll create date-based logic to conditionally set $this->isOnPublicDisplay = false; when visiting our exhibit page outside of our time box.

Now, let’s set some time values:


private $isOnPublicDisplay = true;

function copy_top() {
  if ($this->slug === strtoupper('current-exhibit')) {
    // Event starting, in local time
    $localStart = '2021-10-01 12:00';

    // Event ending, in local time
    $localEnd = '2021-10-31 23:30';

    // Your local timezone; find here:
    // https://www.php.net/manual/en/timezones.php
    $timezone = 'America/Los_Angeles';

    $this->isOnPublicDisplay = false;
  }

  return $this->isOnPublicDisplay;
} // END /**/

function album_top() {
	return $this->isOnPublicDisplay;
} // END /**/

Here, I’ve added variables to hold my opening (start) and closing (end) dates, and my local time zone. My exhibit will open at noon on October 1, and it will close at 11:30 p.m. on October 31. Specifying my local timezone just makes the dates easier to think about.

Now, I’ll add the conditional logic, replacing the line where previously we’ve been setting the display as false. This will be our …

Finished Code


private $isOnPublicDisplay = true;

function copy_top() {
  if ($this->slug === strtoupper('current-exhibit')) {
    // Event starting, in local time
    $localStart = '2021-10-01 12:00';

    // Event ending, in local time
    $localEnd = '2021-10-31 23:30';

    // Your local timezone; find here:
    // https://www.php.net/manual/en/timezones.php
    $timezone = 'America/Los_Angeles';

    if (isset($localStart)) {
      $startDate = new DateTime($localStart, new DateTimeZone($timezone));
      $formattedDate = $startDate->format('g:ia\, \o\n l F j\, Y');
      if ((strtotime('now') < $startDate->format('U'))) {
        echo "<p>The exhibit begins at $formattedDate. Please come back.</p>";

        $this->isOnPublicDisplay = false;
      }
    }

    if (isset($localEnd)) {
      $endDate = new DateTime($localEnd, new DateTimeZone($timezone));
      if ((strtotime('now') > $endDate->format('U'))) {
        echo '
          <p>Our exhibit has ended. We hope to see you again for future exhibits.</p>
        ';

        $this->isOnPublicDisplay = false;
      }
    }
  }

  return $this->isOnPublicDisplay;
} // END /**/

function album_top() {
	return $this->isOnPublicDisplay;
} // END /**/

You may wish to edit the echo statements that message whether the exhibit is pending or expired.

So, what to do with this …

Use it, of course, if you have the need.

I would probably incorporate this with newsletters announcing the upcoming exhibit, the opening of the exhibit, and a reminder a few days before the exhibit closes. Make it a part of your marketing.

Your exhibit might tie into your sales strategy. Signed or numbered prints available during the exhibit, perhaps in exclusive formats.

After the exhibit, you might disperse some or all of the images into other, permanent collections on your site, where the limited edition formats are no longer available, or where images are not being sold at all.

If you’d like to use this to launch an album, but not have it expire, then simply remove the $localEnd logic.

However you manage your event, I hope this has been interesting, or that you’ve at least learned something about PHPlugins.

If you end up using this, I’d love to hear about it. How did you make the event special, and what did you do with the images afterward?

2 Likes