【发布时间】:2016-04-18 23:53:24
【问题描述】:
我只想显示 2015 年发布的资源。
我试过了:
&where=`{"publishedon:":2015}`
但这不起作用。有人可以帮帮我吗?
【问题讨论】:
我只想显示 2015 年发布的资源。
我试过了:
&where=`{"publishedon:":2015}`
但这不起作用。有人可以帮帮我吗?
【问题讨论】:
publishedon 在数据库中保存为 unix 时间。因此,您必须将日期(2015 年)转换为 unix 时间并检查日期范围。
使用以下代码创建一个名为 inyear 的 sn-p:
<?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`]]`
您甚至可以使用 inyear sn-p 的 &where 属性添加额外的 where 子句。
&where=`[[inyear? &year=`2015` &where=`whatever_else_where`]]`
【讨论】:
[[inyear? &year=`2015`] 并查找输出。