We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • This is an auto-generated support/comment thread for UltimateParent.

    Use this forum to post any comments about this addition or any questions you have regarding its use.

    Brief Description:
    Returnt the "ultimate" parent of the current document.
      Studying MODX in the desert - http://sottwell.com
      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
      Join the Slack Community - http://modx.org
      • 7923
      • 4,213 Posts
      Hmm, this snippet didn’t work for me. The getParent returns the id in an array and when the while clause runs, it tried to put the id to the getParent call as an array and I get an parse error. So I did changes from $pid to $pid[’id’] what works for me:
      $top = isset($top) ? $top : 0;
      $id = isset($id) ? $id : $modx->documentIdentifier;
      if($id==$top || $id==0) { return $id; }
      $pid = $modx->getParent($id,1,'id');
      if($pid['id'] == $top) { return $id; }
      while ($pid['id'] != $top && $pid['id'] != "") {
          $id = $pid['id'];
          $pid = $modx->getParent($id,1,'id');
          if($pid['id'] == $top) { return $id; }
      }
      return 0; // if all else fails


        "He can have a lollipop any time he wants to. That's what it means to be a programmer."
      • Snippet updated to 1.2 with those changes doze. I noticed this when testing out a site a few weeks ago; not sure why this isn’t a problem for more people. ?? Anyway, problem resolved.
          • 16511
          • 16 Posts
          Problem NOT resolved. You made a typo when applying the update:

          This line:

          $pid['id'] = $modx->getParent($id,1,'id');


          Should be:

          $pid = $modx->getParent($id,1,'id');


          While we’re at it, the sample usage in the comment at the top is wrong:

          // examples:
          // [[GetUltimateParent?id=`45`&top=`6`]]


          Should be:

          // examples:
          // [[UltimateParent?id=`45`&top=`6`]]
          • My bad, forgot to copy the final corrected version into my text file before uploading. Problem has been corrected, but I kept the version at 1.2.

            I also changed the example in the repository and the code comments.
              • 22815
              • 1,097 Posts
              I really wish you’d at least made it 1.2a, as the older 1.2 almost got into 0.9.5 beta 3, which would have been confusing!
              Thanks for changing the example tho..
                No, I don't know what OpenGeek's saying half the time either.
                MODx Documentation: The Wiki | My Wiki contributions | Main MODx Documentation
                Forum: Where to post threads about add-ons | Forum Rules
                Like MODx? donate (and/or share your resources)
                Like me? See my Amazon wishlist
                MODx "Most Promising CMS" - so appropriate!
                • 28338
                • 46 Posts
                When I call UltimateParent with [!UltimateParent? &top=`2`!] apache gets a lot of load and then times out. Anyone else had any problems?

                Apache version 1.3.33
                PHP version 4.3.10
                • Snippets don’t like & I’ve had a lot of trouble with that when the RTE "helpfully" converts the & to &

                  The solution I use (if I must edit that page with the RTE) is to use the snippet configuration tab instead of arguments in the snippet call. You do it like this:
                  &variableName=Label;type(int, text, etc);default-value &nextVariableName=Label;type;default-value

                  The snippet will use the $variableName and $nextVariableName.

                  Or, you can put the snippet call in a chunk and put the chunk in the document.
                    Studying MODX in the desert - http://sottwell.com
                    Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                    Join the Slack Community - http://modx.org
                    • 28338
                    • 46 Posts
                    Well.. I have the snippet call in a chunk, so that probably is not the problem. Tried calling just [!UltimateParent!] and that worked well, but not if I specify &top. I call WayFinder in the same chunk and that works well. Any ideas?
                      • 28338
                      • 46 Posts
                      Quote from: sottwell at Sep 19, 2006, 07:41 AM

                      &variableName=Label;type(int, text, etc);default-value &nextVariableName=Label;type;default-value


                      So... What’s the equivalent of [[UltimateParent? &top=`2`]] ?

                      BTW, &top takes a document id, right? Is there any way of specifying that I want the parent of a document below a certain level? Like [[UltimateParent? &id=`521` &belowLevel=`2`]]? That would help me a lot.