Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save florianziegler/9acc35a918a007ad278c7cb1befae290 to your computer and use it in GitHub Desktop.
Save florianziegler/9acc35a918a007ad278c7cb1befae290 to your computer and use it in GitHub Desktop.
Get the number of consecutive days of posting in Kirby
// Get number of consecutive days of posting
$num = 1;
$p = $pages->listed()->last();
while( $p ) {
// published = date/time field, substr to only get day accuracy
$date = date_create( substr( $p->published(), 0, 10 ) );
$p = $p->prevListed();
$date_prev = date_create( substr( $p->published(), 0, 10 ) );
$diff = date_diff( $date, $date_prev );
if ( $diff->d === 0 AND $diff->m === 0 AND $diff->y === 0 ) {
// Do nothing -> same day!
}
elseif ( $diff->d === 1 AND $diff->m === 0 AND $diff->y === 0 ) {
$num++;
}
else {
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment