Hi,
is ist possible to show a calculated range of pages?
Example:
I have a page with a field called âyearâ. I need to display all pages with the same year +/- 10 years.
I already managed it to display pages with the same year with the following line:
<?php $werke = page('bibliothek/werke')->children()->filterBy('year',$page->year()->uri());?>
almost thereâŚ
but with this i get no results:
<?php $werke = page('bibliothek/werke')->children()->filterBy('year', '>', strtotime('year - 10'))->filterBy('year', '<', strtotime('year + 10'));?>
(i have set the field as number)
That doesnât make sense
php
Sorry, i´m still super confused and can´t make it work so far:
the year is
<?= $page->date('Y', 'year')?>
and the calculation is:
$werke = $page('bibliothek/werke')->children()->filterBy('year', '>', strtotime('-10 years'))->filterBy('year', '<', strtotime('+10 years'));
Where am i wrong?
As I said above, you have to use a filter with a callback , not filterBy()
. Currently, you are comparing the year field (which in this case probably returns a string) to a unix timestamp. But you have to convert your field value to a Unix timestamp to be able to compare it to another Unix timestamp.
The examples in the cookbook recipe should help (sorry, posted the wrong link above).