2016-01-13 63 views

回答

2

publishedon在数据库中保存为unix时间。所以你必须将你的日期(2015)转换为unix时间,并检查日期范围。

创建一个名为inyear用下面的代码片段:

<?php 
$year = $modx->getOption('year', $scriptProperties, ''); 
$where = $modx->getOption('where', $scriptProperties, false); 
$where = is_array($where) ? $where : json_decode($where, true); 
$where = ($where) ? $where : array(); 

if ($year) { 
    $where[] = array(
     'publishedon:>=' => strtotime('1-1-'.$year), 
     'publishedon:<' => strtotime('1-1-'.($year+1)), 
    ); 
} 
return json_encode($where); 

此之后,你可以调用getRessources与

&where=`[[inyear? &year=`2015`]]` 

你甚至可以添加额外的where子句与&,其中财产的年份片段。

&where=`[[inyear? &year=`2015` &where=`whatever_else_where`]]` 
+0

谢谢。不幸的是,这是行不通的。与你的代码,仍然是我所有的年份都显示 – Jarla

+0

它应该工作,你可以请直接调用** ** inyear **'[[inyear? &year ='2015']'''并查找输出。 – Jako

+0

我完全像你所说的那样调用了片段。没有输出 – Jarla

相关问题