Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sub-Navigation Menu
#10
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>
Reply


Messages In This Thread
Sub-Navigation Menu - by dclawson - 2010-02-18, 12:44:19
Sub-Navigation Menu - by Zegnåt - 2010-02-18, 23:42:37
Sub-Navigation Menu - by dclawson - 2010-02-19, 15:48:53
Sub-Navigation Menu - by caviar - 2010-04-07, 19:46:44
Sub-Navigation Menu - by dclawson - 2010-04-07, 23:30:32
Sub-Navigation Menu - by caviar - 2010-04-08, 23:04:38
Sub-Navigation Menu - by dclawson - 2010-04-26, 20:45:18
Sub-Navigation Menu - by Zegnåt - 2010-04-27, 17:02:13
Sub-Navigation Menu - by RobA - 2010-10-14, 06:08:16
Sub-Navigation Menu - by RobA - 2010-10-15, 06:14:06
Sub-Navigation Menu - by Zegnåt - 2010-10-15, 06:40:35
Sub-Navigation Menu - by RobA - 2010-10-15, 07:10:38
Sub-Navigation Menu - by ccagle8 - 2010-10-15, 10:06:07



Users browsing this thread: 1 Guest(s)