API:getParent

From MODx Wiki

Jump to: navigation, search

Returns the parent record for the id passed.


Usage

  1. array getParent($id=-1, $active=1, $fields='id, pagetitle, description, alias, parent');

Examples

  1. $parent = $modx->getParent(55,1,'pagetitle');

will return the title of the parent of document 55 if the parent is published.

  1. $parent = $modx->getParent(55,0,'id');

will return the parent document's id if it is not published.

From: http://modxcms.com/getparent.html

Source Code

File: manager/includes/document.parser.class.inc.php
Line: 1467
function getParent($pid= -1, $active= 1, $fields= 'id, pagetitle, description, alias, parent') {
        if ($pid == -1) {
            $pid= $this->documentObject['parent'];
            return ($pid == 0) ? false : $this->getPageInfo($pid, $active, $fields);
        } else
            if ($pid == 0) {
                return false;
            } else {
                // first get the child document
                $child= $this->getPageInfo($pid, $active, "parent");
                // now return the child's parent
                $pid= ($child['parent']) ? $child['parent'] : 0;
                return ($pid == 0) ? false : $this->getPageInfo($pid, $active, $fields);
            }
    }
Personal tools