html - PHP - make a link active based on folder name -


this easy 1 i'm getting started php.

i'm attempting create universal header , want use php make links have css class based on folder structure of currant url.

the idea have 3 levels of navigation, level 1 set first folder, level 2 set subfolder, , level 3 set name of php file.

for example if have url www.mysite.com/home/aboutus/history.php?id=1

the option "home" active on level 1 of menu "aboutus" active on second level , "history" active on 3rd level

html

<a href="#"><div class="menu-1-button"> <p class="menu-1-button-text">option1a</p></div></a>  <a href="#"><div class="menu-1-button"> <p class="menu-1-button-text">option1b</p></div></a>  <a href="#"><div class="menu-1-button"> <p class="menu-1-button-text">option1c</p></div></a>  </div>  <div id="selected-option1a"> <div class="sub-menu-2">  <a href="#"><div class="menu-2-button"> <p class="menu-2-button-text">option2a</p></div></a>  <a href="#"><div class="menu-2-button"> <p class="menu-2-button-text">option2b</p></div></a>  <a href="#"><div class="menu-2-button"> <p class="menu-2-button-text">option2c</p></div></a>   </div>  <div id="sub-menu-3">  <a href="#"><div class="menu-3-button"> <p class="menu-3-button-text">option3a</p></div>  <a href="#"><div class="menu-3-button"> <p class="menu-3-button-text">option3b</p></div>  <a href="#"><div class="menu-3-button"> <p class="menu-3-button-text">option3c</p></div>  </div> </div>  <div id="selected-option1b"> <div class="sub-menu-2">  <a href="#"><div class="menu-2-button"> <p class="menu-2-button-text">option2a</p></div></a>  <a href="#"><div class="menu-2-button"> <p class="menu-2-button-text">option2b</p></div></a>  <a href="#"><div class="menu-2-button"> <p class="menu-2-button-text">option2c</p></div></a>   </div>  <div id="sub-menu-3">  <a href="#"><div class="menu-3-button"> <p class="menu-3-button-text">option3a</p></div>  <a href="#"><div class="menu-3-button"> <p class="menu-3-button-text">option3b</p></div>  <a href="#"><div class="menu-3-button"> <p class="menu-3-button-text">option3c</p></div>  </div> </div> 

on header bottom 2 menu levels changed depending on option selected on first menu level, ill give each selected-optionx div property of display:none , use similar technique active class give 1 of selected-option1x divs class of display:block depending on option selected on first menu level.

so want know how give class of "active" depending on currant folders in url using php.

thanks,

frankly don't think you're headed right way here.

it possible request php, end crappy, complex , monolithic structure.

if implement framework, force twist contents fit arbitrary 3 levels structure. end contrieved contents have been put there because tool designed forced so.

besides, end one-page application filled hidden sub-pages.
take longer load , consume more resources, no added benefit since not able display meaningful until whole document loaded.

all being said, here bit of code might show like:

$tree = array (     "optiona" => array (         "optiona1" => array (             "optiona1a" => "",             "optiona1b" => "",             "optiona1c" => ""),         "optiona2" => array (             "optiona2a" => "",             "optiona2b" => "",             "optiona2c" => ""),         "optiona3" => array (             "optiona3a" => "",             "optiona3b" => "",             "optiona3c" => "")),     "optionb" => array (         "optionb1" => array (             "optionb1a" => "",             "optionb1b" => "",             "optionb1c" => ""),         "optionb2" => array (             "optionb2a" => "",             "optionb2b" => "",             "optionb2c" => ""),         "optionb3" => array (             "optionb3a" => "",             "optionb3b" => "",             "optionb3c" => "")));  foreach ($tree $n1 => $l2) foreach ($l2   $n2 => $l3) foreach ($l3   $n3 => $junk) {     echo "<a href=http::/whatever.what/$n1/$n2/$n3.html>...whatever...</a>"; } 

if want word of advice, give on dream of making generic framework.
genericity selling things, , pain implement.
leave marketing guys.


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -