Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • trfletch 598 posts 604 karma points
    Feb 25, 2009 @ 16:34
    trfletch
    0

    Sort list the opposite way round

    I currently have a list of all the child nodes/pages, is there a way in the XSLT to sort them opposite to what they are displayed, for example the pages are as follows. I realise I can arrange them the way I want using the "Sort" function in the Umbraco Content editor but I would rather users could just created a new page and it automatically get displayed as I want:

    Spring 2008
    Summer 2008
    Autumn 2008
    Winter 2008
    new page will go here


    And when I add a new page it will be put to the bottom of the list, but I want the output to be displayed as follows with latest first:

    new pages need to be shown here
    Winter 2008
    Autumn 2008
    Summer 2008
    Spring 2008

    Currently the code I have is as follows:

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Feb 25, 2009 @ 17:15
    Dirk De Grave
    0

    Hi,

    Sorting nodes isn't such a big deal, I'm more worried whether the current nodes will keep their original 'sort order'.

    Here's the syntax for sorting nodes:

    [code]<>
    select="expression"
    lang="language-code"
    data-type="text|number|qname"
    order="ascending|descending"
    case-order="upper-first|lower-first"/>[/code]

    In your case, if you'd want the nodes to be sorted on the name of the node, it would become

    [code][/code]

    It might become a bit more complex in your situation...

    - If the order in which you've created the nodes are 'Spring 2008', 'Summer 2008', ..., 'Winter 2008' (meaning that 'Winter 2008' node has been created as the last of the 4), then sorting on @createDate should do fine, as all new nodes will have a later @createDate then the existing ones and sorting on @createDate descending will do.

    - If this is not the case, you'll need to find another property to use for sorting (And I doubt the node id will help in this case, as @id property is closely related to @createDate) or... sort the nodes using the sort dialog (to put the latest on top) and create an event handler that fires for each new node and puts that node on top (by changing the @sortorder property programmatically).

    Hope this helps.

    Regards,
    /Dirk


  • trfletch 598 posts 604 karma points
    Feb 25, 2009 @ 17:22
    trfletch
    0

    Thanks for the response, I thought this might be a bit more difficult than it seemed. I had thought that sorting by created date might do the trick, I suppose it will be a case of trying it as seeing how it goes. In theory it should work because the site is for a magazine and only new editions should be added. Thanks again.

Please Sign in or register to post replies

Write your reply to:

Draft