kreoton web development

Archive for March, 2008

[PHP] building recursive menu with MySQL and without it

Thursday, March 13th, 2008

Today I decided to share with you with two my function that I use in my code to build navigation menu for websites. First function is to build menu formated in PHP array. First we must format our menu in array like this way:

$menu = array(
	'Home' => $base.'/',
	'Videos' => array (
		'_link' => $base.'/videos/',
		'_submenu' => array (
			'Categories' => array (
				'_link' => $base.'/videos/categories',
				'_submenu' => array (
					'Fun videos' => $base.'/videos/categories/fun_videos',
					'Home videos' => $base.'/videos/categories/home_videos',
				),
			),
			'Popular' => $base.'/videos/popular',
			'Best rated' => $base.'/videos/best-rated',
		),
	),
	'Articles' => array (
		'_link' => $base.'/articles',
		'_submenu' => array (
			'Newest' => $base.'/articles/newest',
			'Archive' => $base.'/articles/archive',
		),
	),
	'Contact Us'=> $base.'/contact_us'
);

Variable $base is holding url to our website and is defined like this:

$base = 'http://www.example.com';

(more…)