We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 11316
    • 81 Posts
    Trying to go up the tree one more step than parent, or even more. Any help would be greatly appreciated or how I could really flush this out.
    I am just trying to wrap my head around the PHP and API. huh

    $parent = $modx -> documentObject[’parent’];
    $grandparent = $modx -> documentObject[’parent’];

    // use the parent in the ditto call
    $ditto_output = $modx->runSnippet("Ditto", array(
    "parents" => $grandparent,
    "tpl" => "tplsubNavfeatured",
    "noResults" => "tplnoResults",
    "sortBy" => "menuindex",
    "sortDir" => "ASC"));

    // output the ditto results
    return $ditto_output;
      • 3749
      • 24,544 Posts
      You might check out the UltimateParent snippet, especially if you want to go beyond the grandparent.

      Otherwise, I think this will work (I changed the variable names to show which are document objects and which are just document ID numbers):

      <?php
      $parentId = $modx->documentObject['parent'];  // get the parent's ID
      $parentObject = $modx->getDocumentObject('id',$parentId); // get the parent object
      $grandparentId = $parentObject['parent']; // get the parent object's parent field (i.e. grandparent's id)
      
      /* if you want to go further */
      $grandparentObject = $modx->getDocumentObject('id',$grandparentId);
      $greatGrandparentId = $grandparentObject['parent'];
      
      // use the grandparent ID in the ditto call
      $ditto_output = $modx->runSnippet("Ditto", array(
      	"parents" => $grandparentId,
      	"tpl" => "tplsubNavfeatured",
      	"noResults" => "tplnoResults",
      	"sortBy" => "menuindex",
      	"sortDir" => "ASC"));
      
      // output the ditto results
      return $ditto_output;
      ?>

        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 11316
        • 81 Posts
        I just want to give you a huge and simple THANK YOU you have really helped me on this, worked perfectly!

        Got room for one more wrapper zinger??
          • 3749
          • 24,544 Posts
          Quote from: Ryan at Nov 14, 2009, 10:36 AM

          I just want to give you a huge and simple THANK YOU you have really helped me on this, worked perfectly!

          Got room for one more wrapper zinger??

          Can’t guarantee I can answer it, but someone probably can. Shoot.
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 11316
            • 81 Posts
            Thanks in advanced for looking at this at least! I really appreciate it.

            // identify the parent
            $parent = $modx -> documentObject[’id’];

            if $parent (is) container (or does it matter?) and has 1 child or less) display = (empty).

            elseif $parent (container has 2 children or more = $wayfinder_output;

            // use the parent in the ditto call
            $wayfinder_output = $modx->runSnippet("Wayfinder", array(
            "startId" => $parent,
            "level" => "1",
            "outerClass" =>"innerway",
            "firstClass" => "active first",
            "textOfLinks" => "menuindex"));

            // output the wayfinder results
            return $wayfinder_output;
              • 3749
              • 24,544 Posts
              Quote from: Ryan at Nov 14, 2009, 10:00 PM

              Thanks in advanced for looking at this at least! I really appreciate it.

              <?php
              // identify the parent
              $parent = $modx -> documentObject['parent'];
              
              $kids = getDocumentChildren($parent);
              
              $numKids = count($kids);
              
              /* if $parent (is) container (or does it matter?) and has 1 child or less) display = (empty). */
              
              if ($numKids <= 1) {
              
                 $wayfinder_output = '';
              
              } else {
              
                  /* elseif $parent (container has 2 children or more = $wayfinder_output; */
              
                  // use the parent in the ditto call
                  $wayfinder_output = $modx->runSnippet("Wayfinder", array(
              	"startId" => $parent,
              	"level" => "1",
              	"outerClass" =>"innerway",
              	"firstClass" => "active first",
              	"textOfLinks" => "menuindex"));
              }
              
              return $wayfinder_output;
              ?>
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
                • 11316
                • 81 Posts
                BobRay thank you again but...hmmm - I think you were testing to make sure I was actually trying to code it. It was fun to figure it out!

                Here is what I did:

                
                // identify the parent
                $parent = $modx -> documentObject['id'];
                $kids = $modx -> getDocumentChildren($parent); (Added $modx -> )
                $numKids = count($kids);
                
                if ($numKids<= 1) { (Changed to $numKids)
                   $wayfinder_output = '';
                
                } else {
                
                    // use the parent in the ditto call
                    $wayfinder_output = $modx->runSnippet("Wayfinder", array(
                	"startId" => $parent,
                	"level" => "1",
                	"outerClass" =>"innerway",
                	"firstClass" => "active first",
                	"textOfLinks" => "menuindex"));
                }
                
                return $wayfinder_output;
                


                Thank you again - it’s been so helpful for guidance on the API! I really do appreciate it!

                Anywhere else I should post all this good stuff?? In case someone else asks?
                  • 3749
                  • 24,544 Posts
                  Not testing, just tired. Sorry about that.

                  Glad you got it worked out. smiley

                  Note that much of that code is deprecated in MODx Revolution, so the Revolution version will look somewhat different.
                    Did I help you? Buy me a beer
                    Get my Book: MODX:The Official Guide
                    MODX info for everyone: http://bobsguides.com/modx.html
                    My MODX Extras
                    Bob's Guides is now hosted at A2 MODX Hosting
                    • 11316
                    • 81 Posts
                    No worries I was really excited to figure it out.

                    Knowing that it is all going to change in Rev - makes me feel like that kid that always showed up late to play ball when everyone was packing to go home. :’(
                      • 3749
                      • 24,544 Posts
                      It shouldn’t be that bad. You’ll use

                      $parent = $modx->resource->get('parent');
                      $kids = $modx->getChildIds($parent);
                        Did I help you? Buy me a beer
                        Get my Book: MODX:The Official Guide
                        MODX info for everyone: http://bobsguides.com/modx.html
                        My MODX Extras
                        Bob's Guides is now hosted at A2 MODX Hosting