Through a combination of some css, and the subnav feature of the nav function (LinkFunctions) I've been working on getting drop-down menus, in my header's navigation. I've figured the basics, but now I have an issue where I want to have a browse by year drop-down menu. You hover over the browse by year, and you get a list of decades, you mouse over a decade, and then a list of years pops up. It works, but I'd like to consolidate my code. Here's what I currently have:
<ul class="dropdown">
<?php
$links = array('Home' => uri(''),
'Browse Items' => array('uri' => 'items',
'subnav_links' => array(
'Oldest First' => 'items/browse?sort_field=Dublin+Core,Date',
'Newest First' => 'items/browse?sort_field=Dublin+Core,Date&sort_dir=d'),
'subnav_attributes' => array('class' => 'subnav')),
'Collections' => array('uri'=>'#', 'subnav_links' => array(
'People' => 'items/browse?collection=4',
'Historic Images ' => uri('items/browse?collection=1'),
'Community Contributions'=> uri('items/browse?collection=3')),
'subnav_attributes' => array('class' => 'subnav')),
'Tags' => uri('items/tags?sort=alpha'),
'Add Your Own'=>uri('contribution'),
'About'=>uri('about'),
'Help'=>uri('help'),
'Browse By Year'=>array('uri'=>'#',
'subnav_links'=>array('1900s'=>array('uri'=>'#',
'subnav_links'=>array(
'1900'=>'items/browse?search=1900',
'1901'=> 'items/browse?search=1901',
'1902'=> 'items/browse?search=1902',
'1903'=> 'items/browse?search=1903',
'1904'=> 'items/browse?search=1904',
'1905'=> 'items/browse?search=1905',
'1906'=> 'items/browse?search=1906',
'1907'=> 'items/browse?search=1907',
'1908'=> 'items/browse?search=1908',
'1909'=> 'items/browse?search=1909'),
'subnav_attributes' => array('class' => 'subnav')),
<!-- Code here from 1910 to 1999 -->
'2000s'=>array('uri'=>'#',
'subnav_links'=>array(
'2000'=>'items/browse?search=2000',
'2001'=> 'items/browse?search=2001',
'2002'=> 'items/browse?search=2002',
'2003'=> 'items/browse?search=2003',
'2004'=> 'items/browse?search=2004',
'2005'=> 'items/browse?search=2005',
'2006'=> 'items/browse?search=2006',
'2007'=> 'items/browse?search=2007',
'2008'=> 'items/browse?search=2008',
'2009'=> 'items/browse?search=2009'),
'subnav_attributes' => array('class' => 'subnav'))),'subnav_attributes'=>array('class'=>'decade')));
echo nav($links,4); ?></ul>
However instead of writing that all out I'd like to use something like
<?php
$yearlist="array(";
foreach (range(1900, 2009) as $number) {
$last=substr($number,-1);
if ($last==0){$yearlist.= "'".$number."s'=>array('uri'=>'#', 'subnav_links'=>array('".$number."'=>'/throughtime/items/browse?search=".$number."',";
}
else if ($last==9){$yearlist.= "'".$number."'=> '/throughtime/items/browse?search=".$number."'),'subnav_attributes' => array('class' => 'subnav')),";
}
else{
$yearlist.= "'".$number."'=> '/throughtime/items/browse?search=".$number."',";
}
}
$yearlist=rtrim($yearlist,",");
$yearlist.="),'subnav_attributes'=>array('class'=>'year');"; ?>
This generates the string for the code above for all the years. I'd like to insert the variable $yearlist
into 'Browse By Year'=>array('uri'=>'#', 'subnav_links'=>$yearlist
, but I haven't figured it out. How do I insert a variable like that into the $links variable that's used in the nav function.?