We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17895
    • 209 Posts
    I found that I needed this change in the UltimateParent snippet, so I post it here if someone else need it (and one from Italian forum will need soon smiley ).

    I added a parameter that controls if only active (published) parents are scanned. I need this when getting the parent language folder in a typical multi-language tree structure (Susan’s style: one subfolder UNPUBLISHED for each language).

    Here is the code:

    <?php
    // UltimateParent - snippet for MODx 0.9x
    // Travels up the document tree from the current document
    // to return the "ultimate" parent
    // March 2006 - [email protected]
    // Bug fix Sept 17, 2006 - Jason Coward <[email protected]>
    // Added active field Dec 23, 2006 - Daniele "MadMage" Calisi <[email protected]>
    // Released to the Public Domain, use as you like
    // arguments:
    // &id      - the id of the document whose parent you want to find
    // &top     - the top of the search 
    // &active - 1 (default) if only active parents can be returned, 0 otherwise
    // examples:
    // [[UltimateParent? &id=`45` &top=`6`]]
    // will find the first parent of document #45 under document #6
    // if id == 0 or top == id, will return id.
    // you can use this as the startDoc for DropMenu to create specific submenus.
    
    $top = isset($top)?$top:0;
    $id = isset($id)?$id:$modx->documentIdentifier;
    $active = isset($active)?$active:1;
    if($id==$top || $id==0) { return $id; }
    $pid = $modx->getParent($id,$active,'id');
    if($pid['id'] == $top) { return $id; }
    while ($pid['id'] != $top) {
        $id = $pid['id'];
        $pid = $modx->getParent($id,$active,'id');
        if($pid['id'] == $top) { return $id; }
    }
    return 0; // if all else fails
    ?>
    


    And here is how I use it in WayFinder snippet call:

    [!Wayfinder? &startId=`[[UltimateParentPlus? &active=`0`]]` &hideSubMenus=`TRUE`!]
    


    Multilanguage content is becoming an easy thing... more news soon... smiley
      Daniele "MadMage" Calisi