Back to CategoryNode class

Method getSibling

public \Joomla\CMS\Categories\CategoryNode|null
getSibling
(mixed $right = true)
Returns the right or left sibling of a category
Parameters
  • bool $right If set to false, returns the left sibling
Returns
  • \Joomla\CMS\Categories\CategoryNode|null CategoryNode object with the sibling information or null if there is no sibling on that side.
Since
  • 1.6
Class: CategoryNode
Project: Joomla

Method getSibling - Source code

/**
 * Returns the right or left sibling of a category
 *
 * @param   boolean  $right  If set to false, returns the left sibling
 *
 * @return  CategoryNode|null  CategoryNode object with the sibling information or null if there is no sibling on that side.
 *
 * @since   1.6
 */
public function getSibling($right = true)
{
    if (!$this->_allChildrenloaded) {
        $temp = $this->_constructor->get($this->id, true);
        $this->_children = $temp->getChildren();
        $this->_leftSibling = $temp->getSibling(false);
        $this->_rightSibling = $temp->getSibling(true);
        $this->setAllLoaded();
    }
    if ($right) {
        return $this->_rightSibling;
    } else {
        return $this->_leftSibling;
    }
}