We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 349
    • 76 Posts
    Hi,
    i tried the firstChildRedirect snippet, but it seems not to work correctly.
    I have this structure:
    +mainfolder
      ++subfolder
       +++subpage
      ++subpage
      ++anothersubpage
    

    When i put the snippet in the mainfolder and click on the link at the webpage the anothersubpage appears.
    How to get to the subfolder?

    I modified the snippet by changing this:
    /* Get children sorted
     * FIXME: getActiveChildren is depecrated in 1.0
     */
    $children= $modx->getActiveChildren($docid, $sortBy, $sortDir);
    $targetid = isset ( $children[0]['id'] ) ? $children[0]['id'] : $default;
    $url = $modx->makeUrl($targetid,'','','full');
    
    return $modx->sendRedirect($url);

    to this:
    $children= $modx->getChildIds($docid, 1);
    $targetid = $children[0];
    $url = $modx->makeUrl($targetid,'','','full');
    return $modx->sendRedirect($children[0]);

    but then the resulting url doesn´t contain the alias, but the id of the subfolder.

    How do i fix this?
      • 22303 MODX Staff
      • 10,725 Posts
      I think you may have posted the wrong snippets of code; they are identical other than the comments in them...
        • 349
        • 76 Posts
        Quote from: OpenGeek at May 07, 2010, 09:43 AM

        I think you may have posted the wrong snippets of code; they are identical other than the comments in them...
        I modified the code snippets above.
          • 22303 MODX Staff
          • 10,725 Posts
          The second one isn’t using $url for sendRedirect(); that’s why...
            • 349
            • 76 Posts
            yup. you are right.