2011-11-08, 23:11:42
I want to add this feature to GetSimple Core for 3.1, but also wanted to show a bit of code for those that might want this functionality in 3.0 (feel free to tweak the code in the comments)
Code:
function get_subpages($thisparent, $current) {
$path = GSDATAPAGESPATH;
$dir_handle = opendir($path);
$filenames = array();
while ($filename = readdir($dir_handle)) {
$filenames[] = $filename;
}
closedir($dir_handle);
$count=0;
$pagesSubArray = array();
if (count($filenames) != 0) {
foreach ($filenames as $file) {
if ($file == "." || $file == ".." || is_dir($path . $file) || $file == ".htaccess" ) {
// not a page data file
} else {
$data = getXML($path . $file);
if ( $data->private != 'Y' && (
$thisparent == (string)$data->url ||
$thisparent == (string)$data->parent
)
) {
$pagesSubArray[$count]['menuStatus'] = (string)$data->menuStatus;
$pagesSubArray[$count]['menuOrder'] = (string)$data->menuOrder;
$pagesSubArray[$count]['menu'] = (string)$data->menu;
$pagesSubArray[$count]['parent'] = (string)$data->parent;
$pagesSubArray[$count]['title'] = (string)$data->title;
$pagesSubArray[$count]['url'] = (string)$data->url;
$count++;
}
}
}
}
$li = null;
$pagesSorted = subval_sort($pagesSubArray,'menuOrder');
if (count($pagesSorted) > 0) {
foreach($pagesSorted as $x) {
$x_url = find_url($x['url'], $x['parent']);
if ($x['url'] == $current) {
$klass = ' current ';
} else {
$klass = null;
}
if ($x['menu'] == '') {
$x['menu'] = $x['title'];
}
$li .= '<li class="'.$klass.'" ><a href="'.$x_url.'" >'.$x['menu'].'</a></li>';
}
}
echo $li;
}