Last active
November 7, 2022 06:43
-
-
Save florianziegler/9acc35a918a007ad278c7cb1befae290 to your computer and use it in GitHub Desktop.
Get the number of consecutive days of posting in Kirby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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