diff --git a/README.md b/README.md new file mode 100644 index 0000000..ad15d39 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# ddGetParentId + +Gets the parent ID of the required level. +___ +Visit the following [link](http://code.divandesign.biz/modx/ddgetparentid) to read the documentation, instructions & changelog. \ No newline at end of file diff --git a/ddGetParentId.php b/ddGetParentId.php new file mode 100644 index 0000000..ad917eb --- /dev/null +++ b/ddGetParentId.php @@ -0,0 +1,40 @@ +documentIdentifier; +$level = isset($level) ? $level : 1; +$toPlaceholder = (isset($toPlaceholder) && $toPlaceholder == '1') ? true : false; +$placeholderName = isset($placeholderName) ? $placeholderName : 'ddParent'; + +//Если нужно получить самый последний, задаём глубину 10 +if ($level == 'ultimate'){$level = 10;} + +//Получаем последнего родителя +$parent = array_pop($modx->getParentIds($id, $level)); + +//Если задан шаблон, выводим по шаблону +if (isset($tpl)){$parent = $modx->parseChunk($tpl, array('id' => $parent),'[+','+]');} + +//Если надо, выводим в плэйсхолдер, или просто возвращаем +if ($toPlaceholder){ + $modx->setPlaceholder($placeholderName, $parent); +}else{ + return $parent; +} +?> \ No newline at end of file