function get_parent_ids($parent_id) { $ids[] = $parent_id; if (is_parent($parent_id) != false) { $parent_ids = get_parent_ids(is_parent($parent_id)); $ids = array_merge($ids, $parent_ids); } //is_parent( $parent_id ) != false return $ids; }
/** * Function to work out root parent * * @access public * @param integer $page_id * @return integer ID of the root page * **/ function root_parent($page_id) { global $database; // Get page details $sql = 'SELECT `parent`, `level` FROM `' . TABLE_PREFIX . 'pages` WHERE `page_id` = ' . $page_id; $query_page = $database->query($sql); $fetch_page = $query_page->fetchRow(MYSQL_ASSOC); $parent = $fetch_page['parent']; $level = $fetch_page['level']; if ($level == 1) { return $parent; } elseif ($parent == 0) { return $page_id; } else { // Figure out what the root parents id is $parent_ids = array_reverse(get_parent_ids($page_id)); return $parent_ids[0]; } }
function get_page_trail($page_id) { return implode(',', array_reverse(get_parent_ids($page_id))); }