2010-10-15, 06:14:06
RobA Wrote:Sorry for the thread necromancy.
I want to know if there are sub-pages to a page. Typically these subpages would NOT be in the menu tree.
I'd like a function: get_child_slugs('page-slug')
that returns an array of child page slugs or null so I could for-each through them and build a menu (after content) listing all the child pages.
I see the code here should do this (or is close). Do I have to implement it as a plugin or can I just include this stuff in a custom functions.php?
-Rob A>
I don;t know how correct it is to respond to myself, but I figured I'd post the code I went with. I put the following function in my functions.php file of my theme:
Code:
function return_child_data()
{
$slug=return_page_slug();
$path="data/pages/";
$data='';
$count=0;
$morderArray = array();
if (is_dir($path))
{
if ($dh = opendir($path))
{
while (($file = readdir($dh)) !== false)
{
if($file!="." AND $file!=".." AND $file!=".htaccess")
{
$pathtofile="$path$file";
$da = @fopen($pathtofile,"r");
$data=getXML($pathtofile);
if ($data->parent != '')
{
if (strcasecmp($data->parent, $slug) == 0)
{
$node=$data->children();
//print_r($node);
$morderArray[$count]['slug'] = (string)$node->url;
$morderArray[$count]['title'] = (string)$node->menu;
$count++;
}
}
@fclose($da);
}
}
closedir($dh);
}
}
return($morderArray);
}
And use this in a page template php code chunk like so:
Code:
$subpagelist = return_child_data();
foreach($subpagelist as $subpage) {
echo $subpage['slug']; // echos the subpage slug string you can use/append as a URL
echo $subpage['title']; // echos the subpage title string you can use a a label
}
-Rob A>