Skip to content

Instantly share code, notes, and snippets.

@hearvox
Created November 8, 2017 23:13
Show Gist options
  • Select an option

  • Save hearvox/2375074b78210c51b8151c501a92e2ba to your computer and use it in GitHub Desktop.

Select an option

Save hearvox/2375074b78210c51b8151c501a92e2ba to your computer and use it in GitHub Desktop.
Advent calender displays one new audio piece per day
<?php
/*
* Display a new item every day of current month (like an Advent calendar).
* If day has arrived: display the article HTML.
* If day hasn't arrived, print default HTML.
* Restrict numbers to total days in current month.
*
* Compares an array's key (day number) to current day of month.
* Made for Hearing Voices page "Xmas: HV Holiday Stories" (2016).
* @see https://hearingvoices.com/audio/xmas/
*
* Uses "Cubes Advent Calendar" scripts from Codrops:
* @see https://tympanus.net/codrops/2016/11/09/cubes-advent-calendar/
*
* Uses these files:
* @see https://hearingvoices.com/news/wp-content/uploads/2016/12/xmas.css
* @see https://hearingvoices.com/news/wp-content/uploads/2016/12/xmas.js
*/
// Set timezone; get today's day of month and total days in month.
date_default_timezone_set('America/New_York');
$day_of_month = (int) date( 'j' );
// $days_in_month = (int) date( 't' );
// $day_of_month = 12; // Define var value to test.
$days_in_month = 25; // Day of Christmas in December.
$month = 'Dec';
// Compare array key (day number) to current day of month.
foreach ($day_arr as $day => $info) {
$color = ($day % 2 == 0) ? 'cc0019' : '1c2d3f';
if ( $day <= $day_of_month ) { // Display article HTML.
?>
<div class="cube" data-bg-color="#<?php echo $color ?>" data-title="<?php echo $info ?>"></div>
<?php
} elseif ( $day <= $days_in_month ) { // Display default HTML.
?>
<div class="cube" data-inactive data-bg-color="#6161616" data-title="Coming <?php echo $month . ' ' . $day ?>"></div>
<?php
} else {
break;
}
}
/*
Above PHP goes inside this div:
<div class="calendar">
<!-- PHP goes here. -->
</div>
<!-- Example of one item: -->
<article class="content__block"><?php $day_arr[21] = 'Homeless: My Name'; ?>
<h3 class="content__title">Homeless: My Name Is</h3>
<p class="content__description">Voices in the Minnesota <a href="http://hearingvoices.com/2008/08/land-of-10k-homeless-npr/">&ldquo;Land of 10,000 Homeless&rdquo;</a> series, by <a href="http://www.voicesofthestreets.org/Voices%20of%20the%20Streets/Who%20We%20Are.html">Andrew Turpening</a> and <a href="https://somethingsparks.com/">Danny Burke</a> <small>( <em><a href="http://www.npr.org/templates/story/story.php?storyId=91881310">Day to Day</a></em>)</small>.
<?php echo do_shortcode( '[audio src="http://download.npr.org/anon.npr-mp3/npr/day/2008/07/20080702_day_05.mp3" preload="metadata"]' ); ?></p>
<p class="content__meta">by <a href="http://www.voicesofthestreets.org/">Voices in the Streets</a></p>
</article>
*/
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment