Hi guys,
Hope you can help me with this:
QUESTION 1 – Sort by "publishedOn"
-----
I've been implementing this feature (Mark Hamster, Reply #1 in this thread) with success, but need to sort by "publishedOn".
I already tried to insert
&sortby=`{"publishedon":"DESC"}
in my template with no luck.
Looks like this
[[press? &tpl=`tplBlog` &sortby=`{"publishedon":"DESC"}`]]
Whats wrong?
QUESTION 2 – How to output "publishedOn" for each children
-----
In addition – when I output "publishedon" at my frontend with this in my chunk:
<p>[[*publishedon]] - [[+content]]</p>
...
...all my children prints the "publishedon" for the parent, which is the same date for all children. How do I output the "publishedon"-date for each child?
My code is here:
SNIPPET - "press"
---
<?php
// First fetch all the children of the current resource
$children = $modx->resource->getMany('Children');
// Check if there are any. If not, return false
if (!$children) { return false; }
// Check if there is a tpl set, if not return an error
$tpl = $modx->getOption('tpl',$scriptProperties,'');
if (!$tpl) { return 'No template given.'; }
// Start the output
$o = '<h2>[[*pagetitle]]</h2><ul>';
// Look through the results...
foreach ($children as $child) {
// ... fetching the needed info...
$out = array(
'id' => $child->get('id'),
'pagetitle' => $child->get('pagetitle'),
'menutitle' => $child->get('menutitle'),
'content' => $child->get('content'),
'longtitle' => $child->get('longtitle'));
// ... and adding it to the output as placeholders in the chunk
$o .= $modx->getChunk($tpl,$out);
}
// Don't forget to close the list
$o .= '</ul>';
// Return the output
return $o;
CHUNK - tplBlog
---
<p>[[+content]]</p>
<p>[[*publishedon]]</p>
TEMPLATE - press
---
[[press? &tpl=`tplBlog` &sortby=`{"publishedon":"DESC"}`]]