Date field (online from, to)

Hi. I’m trying to do an Date field which allows to keep a page online from a specific date to another. Has anyone an idea ? I have no clue how to start :smiley: And so far I didnt find something like this in the docs …

I belive kirby doesnt support that at this moment.

I wrote some pseudocode how i would do that:

<?php foreach($page->children()->visible() as $p) : ?>
   <?php if($p->from() <= time() && $p->to() >= time()) : ?>
      <div>
         HTML of list element
      </div>
   <?php endif; ?>
<?php endforeach; ?>

The page wouldn´t be displayed in the overview anymore if time() runs out of the restrictions $p->from() and $p->to().

Okay, did u test this code ? Im going to implement it!
Mercii

No i didn´t test it. Could be that you have to convert your date fields “from” and “to” to unix timestamps to compare it with the actual unix timestamp “time()”. Then it should work.

Maybe add some default values in case from or to are not set for a page: http://getkirby.com/docs/cheatsheet/field-methods/or

You could also utilize $page->hide() and something like the following to make your page visible and assign it the highest sorting number your page (untested):

$page->sort($page->siblings()->visible()->last()->num() + 1)

when in used modified() it didnt work, now i used:
<?php if($p->date('dmY' , 'from') <= date('dmY') && $p->date('dmY' , 'to') >= date('dmY')) : ?>

to get the right format and it works.