We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38359
    • 93 Posts
    Hi there,

    I'm trying to use getResources to get info from the nth child of a parent resource.
    Is there an easy way to do this or can anyone point me in the direction of a snippet that can get the id of the nth child (where I can specify n, obviously).

    Thanks in advance!
      • 28120
      • 380 Posts
      This may not be a method recommended by purists but one approach would be

      1. Use the tpl_N parameter where N = 9
      2. In the standard tpl leave the chunk blank
      3. Set the limit = 9

      The other way would be to write some SQL to get the 9th row via offset and return the resource id of that row.
        • 38359
        • 93 Posts
        OK this is actually pretty easy.

        Just make a snippet to read all the child page ids for a given resource into an array and then return the nth record.

        So snippet (getNthChild) will look like:
        $array_child_ids = $modx->getChildIds($parentId,1,array('context' => 'web'));
        return $array_child_ids[$n];


        And getResources call will look something like like:
        [[!getResources? &resources=`[[!getNthChild? &parentId=`9` &n=`1`]]` ]]