I have a bit of code, it works to get recent posts from Discuss forums in MODX.
<?php
$discuss = $modx->getService('discuss','Discuss',$modx->getOption('discuss.core_path',null,$modx->getOption('core_path').'components/discuss/').'model/discuss/');
if (!($discuss instanceof Discuss)) return true;
$c = $modx->newQuery('disPost');
$c->limit(10);
$c->sortby('createdon', 'DESC');
$posts = $modx->getCollection('disPost', $c);
foreach ($posts as $post) {
$temp = $post->toArray();
$temp['url'] = $post->getUrl();
// call chunks or what you want
$out[] = $modx->getChunk('rowTpl', $temp);
}
return implode("\n", $out);
它有效,但它不完美。例如,我想过滤掉私人消息,而在帖子级别这不起作用,帖子级别没有私人标志。
所以我需要做的是抓取线程,对私有或否进行排序,然后获取该数据并通过 createdon 查找帖子并排序 DESC,因此基本上是在这个 db 调用之前的另一个例程。
有人有想法么?任何帮助,将不胜感激!