Sort article by date
I have a fairly basic script that should sort articles in folders by start-date. The sorting is not working. I am using this script on a different site and it is working fine. Any help would be appreciated. Here is what I have:
#set ($year = $_XPathTool.selectSingleNode($contentRoot, "/system-index-block//system-folder[@current and not(@reference)]"))
#set ($articles = $_XPathTool.selectNodes($year, "system-folder[position() <= last()-1]/system-page[path != '/_internal/base-assets/article']"))
$_SortTool.addSortCriterion("start-date", "", "number", "ascending", "")
$_SortTool.sort($articles)
#foreach ($article in $articles)
#set ($startDate = $_DateTool.getDate($article.getChild("start-date").value))
$startDate<br />
#end
You can see here that the articles are not being sorted: http://news.siu.edu/2014/
Here, where the same script is applied, the articles are being sorted: http://coas.siu.edu/news/archive.html
When I test out just outputting the actual start date that is not transformed, they are not sorted.
Comments are currently closed for this discussion. You can start a new one.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
1 Posted by Ryan Griffith on 30 Jul, 2014 04:54 PM
Hi,
I was taking a look at the link you provided and it appears as though the events are being sorted. Were you able to figure things out with your Format?
Please let me know if you have any questions.
Thanks!
2 Posted by lizhunter on 30 Jul, 2014 05:12 PM
Hi Ryan. On news.siu.edu/2014<http://news.siu.edu/2014> the articles start with May, and then as you scroll down they aren't in order by month...and I believe One month appears twice.
Sent from my iPhone
3 Posted by Ryan Griffith on 30 Jul, 2014 06:21 PM
Ah, my apologies for overlooking the incorrect ordering, I am seeing it now.
When you have a moment, please attach your Format along with a sample of the XML being applied to it so I can do some local testing. The sample XML can be obtained by using the Preview Options when editing the Format.
Please let me know if you have any questions.
Thanks!
4 Posted by lizhunter on 30 Jul, 2014 07:02 PM
Sure, here are the XML and format files. These are a little different from what I posted on the forum, as I was trying to shorten it up for that. This format is the full format. I have a part commented out where I was testing just outputting the date, if that helps any. Thanks.
5 Posted by Ryan Griffith on 31 Jul, 2014 01:46 PM
Hi,
I believe the the sorting issue may be due to the fact that the pages are within month folders, which are also not ordered. I think the best solution would be to sort and loop over the months, and sort and loop over the articles within each month. I reworked your Format a bit and came up with the attached Format, which appears to be sorting correctly now.
Note: you may need to tweak the sorting order for the months and/or articles depending on your needs.
Please let me know if you have any questions.
Thanks!
6 Posted by lizhunter on 31 Jul, 2014 02:21 PM
I was thinking that might be the problem but wasn’t coming up with a good solution. Thank you! I’ll check it out and let you know if I have questions.
LIZ HUNTER
Webmaster
WEB COMMUNICATIONS
UNIVERSITY COMMUNICATIONS
MAIL CODE 6819
SOUTHERN ILLINOIS UNIVERSITY
1220 DOUGLAS DRIVE
CARBONDALE, ILLINOIS 62901
[email blocked]<mailto:[email blocked]>
P: 618/453-2820
SIU.EDU<http://siu.edu/>
7 Posted by Ryan Griffith on 31 Jul, 2014 05:29 PM
Sounds good, Liz, please keep me posted on how the updated Format works out.
Thanks!
8 Posted by lizhunter on 31 Jul, 2014 07:53 PM
Nearly perfect! Thanks! I just need to add an if statement to not show months that don’t have content yet (future months). I should be able to handle that. Thanks again. You’re always so helpful.
LIZ HUNTER
Webmaster
WEB COMMUNICATIONS
UNIVERSITY COMMUNICATIONS
MAIL CODE 6819
SOUTHERN ILLINOIS UNIVERSITY
1220 DOUGLAS DRIVE
CARBONDALE, ILLINOIS 62901
[email blocked]<mailto:[email blocked]>
P: 618/453-2820
SIU.EDU<http://siu.edu/>
9 Posted by Ryan Griffith on 31 Jul, 2014 07:59 PM
Thank you for following up, Liz. I am glad to hear the updated Format did the trick.
Regarding that
#if
statement. What you could do is move the#if ($articles.size() > 0)
statement within the listMonthArticles macro to the listMonths macro:Please let me know if you have any questions.
Thanks!
Ryan Griffith closed this discussion on 20 Aug, 2014 01:08 PM.