Copied to clipboard

Flag this post as spam?

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


  • Mathijs 27 posts 60 karma points
    Feb 18, 2011 @ 00:30
    Mathijs
    0

    How to get latest nodes programmatically?

    Dear community,

    I have under my media section a special folder with uploads. Stuctured as folllowing:

    Root

    • - Special folder
    • - - Subfolder
    • - - File 1 (created 13 feb)
    • - - File 4 (created 15 feb)
    • - - Sub-Subfolder
    • - - - File 2  (created 14 feb)
    • - - - File 3  (created 14 feb)
    • - - - File 5  (created 16 feb)
    • - Other folder
    What I try to achieve is to get the 5 latest uploads from this "special folder". Currently I have a recursive function which gives me the following result: (which obviously is the order of the tree)
    • File 1
    • File 4
    • File 2
    • File 3
    • File 5
    Of course.. that's not what I want. I would like to have a result for example:
    1. File 5
    2. File 4
    3. File 3
    4. File 2
    5. File 1
    My best guess just would be creating a huge collection of all nodes under the special folder, and later on sort this collection using a date entity.  However, that doesn't sound too smart and with many files I think it's a waste of resources collecting all items to eventually display 5 of them.
    Anyone? Thanks in advance!

  • Daniel Bardi 927 posts 2562 karma points
    Feb 18, 2011 @ 01:21
    Daniel Bardi
    0

    In xslt, you can sort the nodes by created date within a for-each loop.

    <xsl:for-each .... >
      <xsl:sort select="./@createDate" order="descending"/>
      ... do stuff ...
    </xsl:for-each>

  • Mathijs 27 posts 60 karma points
    Feb 18, 2011 @ 01:23
    Mathijs
    0

    Thanks for your reply Daniel. I'm trying to achieve this in a user control.

  • Mathijs 27 posts 60 karma points
    Feb 21, 2011 @ 20:34
    Mathijs
    0

    For those looking for a solution in this topic. I solved it like this:

    Wrote a class mediaNodes which recursively collects all files falling under a parent node. Return a List object with a file properties.

    In actual user control I sort and limit the results.

     

Please Sign in or register to post replies

Write your reply to:

Draft