Pages Menu – In Array

These functions burned my 2 days googling until I decided to make my own. I hope it will help somebody.

function getChild(&$arrParent, $dyPages){
	if (!empty($dyPages) && (count($dyPages) > 0)){
		$dyPages2 = $dyPages;
		foreach ($dyPages as $k => $obj){
			if ($obj->post_parent == $arrParent['id']){
				unset($dyPages2[$k]);
				$arrParent['child'][$obj->ID] = array(
													'id' => $obj->ID,
													'menu_order' => $obj->menu_order,
													'post_title' => trim($obj->post_title)
												);
				getChild($arrParent['child'][$obj->ID], $dyPages2);
			}
		}
	}
}

function getParents(){
	$pages = get_pages();
	$dyPages = $pages;
	$arrParent = array();
	foreach ($pages as $k => $obj){
		if ($obj->post_parent === 0){
			unset($dyPages[$k]);
			$arrParent[$obj->ID] = array('id' => $obj->ID, 'menu_order' => $obj->menu_order, 'post_title' => trim($obj->post_title));
		}
	}
	foreach ($arrParent as $k => $v){
		getChild($arrParent[$k], $dyPages);
	}
	return $arrParent;
}

Tags:

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!

You must be logged in to post a comment.