We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21136
    • 103 Posts
    I am using the [!FirstChild!] snippet and works great - below is the script.

    But have a request...

    First, I am using friendly URL’s.

    I use many folders on my site. Each of these folders have an ’index.html’ page, along with other pages. The ’index.html’ page is not always the "firstchild" - so how can I have the script look for the alias ’index.html’ instead?

    Regards,

    Ken

    -----------------------------
    if (!isset($id)) $id=$modx->documentIdentifier;
    $children=$modx->getActiveChildren($id,’menuindex’,’ASC’);
    if (!$children===false)
    {
    $firstChild = $children[0];
    $firstChildUrl = $modx->makeUrl($firstChild[’id’]);
    }
    else
    {
    $firstChildUrl = $modx->makeUrl($modx->config[’site_start’]);
    }
    return $modx->sendRedirect($firstChildUrl);
    -----------------------------

      • 32982
      • 674 Posts
      test it (if use sufix like html and the alias is index else change alias="index"to alias="index.html")
      if (!isset($id)) $id=$modx->documentIdentifier;
      $children = $modx->getDocumentChildren($id,1,0,’id,alias’, ’alias="index"’,’pagetitle’, ’DESC’);
      $childrenCount = count($children);
      if (!$children===false)
      {
      $firstChild = $children[0][’id’];
      $firstChildUrl = $modx->makeUrl($children[0][’id’]);
      }
      else
      {
      $firstChildUrl = $modx->makeUrl($modx->config[’site_start’]);
      }
      return $modx->sendRedirect($firstChildUrl);
        Jabiertxof (formerly XYZVISUAL)
        My bussines: http://marker.es
        https://www.youtube.com/user/jabiertxof/videos
        • 21136
        • 103 Posts
        Javier,

        Thanks for the script but it’s not working. Now I get redirected back to the site’s root.

        I have a folder named "software".

        In the folder I have "index" and "test". I am using the suffic "htm" for the page extension.

        when I go to the http://www.name.com/software/ is redirects me to the home page. The original script works fine as long as the "index" page has lowest id within the folder - but your new script directs me back to the home page no matter what I do.

        Any ideas?

        Thanks,

        Ken
          • 32982
          • 674 Posts
          a little error fixed test it now (change the upper code)
            Jabiertxof (formerly XYZVISUAL)
            My bussines: http://marker.es
            https://www.youtube.com/user/jabiertxof/videos
            • 32982
            • 674 Posts
            the problem whith this snippets are all folders need a index page....
              Jabiertxof (formerly XYZVISUAL)
              My bussines: http://marker.es
              https://www.youtube.com/user/jabiertxof/videos
              • 32982
              • 674 Posts
              this could be used in the template and only redirects if has the page a subpage whith the alias index if not dont redirect and you dont need to use the snippet in all folders siply put in the template
              hi
              test it (if use sufix like html and the alias is index else change alias="index"to alias="index.html")
              if (!isset($id)) $id=$modx->documentIdentifier;
              $children = $modx->getDocumentChildren($id,1,0,’id,alias’, ’alias="index"’,’pagetitle’, ’DESC’);
              $childrenCount = count($children);
              if (!$children===false)
              {
              $firstChild = $children[0][’id’];
              $firstChildUrl = $modx->makeUrl($children[0][’id’]);
              $modx->sendRedirect($firstChildUrl);
              }
              else
              {

              }
                Jabiertxof (formerly XYZVISUAL)
                My bussines: http://marker.es
                https://www.youtube.com/user/jabiertxof/videos
                • 21136
                • 103 Posts
                COOL!!!

                Thanks so much. It works perfectly smiley

                Regards,

                Ken