1
我想只显示刊登在2015年如何使用getResources(Modx)仅显示特定年份的资源?
我试过资源:
&where=`{"publishedon:":2015}`
但是,这是行不通的。有谁能够帮助我?
我想只显示刊登在2015年如何使用getResources(Modx)仅显示特定年份的资源?
我试过资源:
&where=`{"publishedon:":2015}`
但是,这是行不通的。有谁能够帮助我?
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`]]`
谢谢。不幸的是,这是行不通的。与你的代码,仍然是我所有的年份都显示 – Jarla
它应该工作,你可以请直接调用** ** inyear **'[[inyear? &year ='2015']'''并查找输出。 – Jako
我完全像你所说的那样调用了片段。没有输出 – Jarla