php - keeping active page using include_once to include site navigation -
another, silly, question. have in-depth navigation menu on clients site. don't mind doing hard slog changing pages , links .php - save mucho time in future. want use <?php include_once("nav.php"); ?>
pull every page. @ moment parent item active highlighted depending on child page being viewed. menu structure part of each of .html page.
html markup:
<div id="navigation-wrapper"> <nav id="main-navigation"> <ul class="main-menu"> <li><a href="index.html" title="home" class="active-page"><span aria-hidden="true" class="li_display nav_icon"></span>about</a> <ul> <li><a href="about.html">corporate profile</a></li> <li><a href="about.html#bod">board of directors</a></li> <li><a href="divisions.html">operating divisions</a></li> <li><a href="organisation.html">organisational chart</a></li> <li><a href="corporate-downloads.html">corporate documentation</a></li> </ul> </li> <li><a href="#"><span aria-hidden="true" class="li_news nav_icon"></span>investor</a> <ul> <li><a href="investor-overview.html">overview</a></li> <li><a href="investor-financial.html">financial</a></li> <li><a href="investor-news.html">news</a></li> <li><a href="investor-events.html">events</a></li> <li><a href="investor-general.html">general</a></li> <li><a href="http://alertscentral.com/" target="_blank">register alerts</a></li> </ul> </li> <li><a href="#"><span aria-hidden="true" class="li_bulb nav_icon"></span>products</a> <ul> <li><a href="mecer.html">mecer</a></li> <li><a href="#">hardware </a> <ul> <li><a href="http://www.apc.com/site/apc/index.cfm" target="_blank">apc</a></li> <li><a href="acer.html">acer</a></li> <li><a href="asus.html">asus</a></li> <li><a href="http://www.e-beam.com/home.html" target="_blank">e-beam</a></li> <li><a href="fujitsu.html">fujitsu</a></li> <li><a href="huawei.html">huawei</a></li> <li><a href="lenovo.html">lenovo</a></li> <li><a href="microsoft.html">microsoft</a></li> <li><a href="nec.html">nec</a></li> <li><a href="samsung.html">samsung</a></li> <li><a href="toshiba.html">toshiba</a></li> </ul> </li>`enter code here` <li><a href="#">mustek energy</a> <ul> <li><a href="panels.html">solar panels</a></li> <li><a href="led.html">led lighting solutions</a></li> </ul> </li> <li><a href="#">mustek solutions</a> <ul> <li><a href="cloud.html">mustek cloud computing</a></li> <li><a href="mustek.html#branding">mustek digital signage</a></li> <li><a href="mustek.html#pos">mustek pos solutions</a></li> <li><a href="mustek.html#security">mustek security technology</a></li> </ul> </li> <li><a href="#">networking solutions</a> <ul> <li><a href="dlink.html">d-link</a></li> <li><a href="huawei.html">huawei</a></li> <li><a href="miniflex.html">miniflex</a></li> <li><a href="nec.html">nec</a></li> <li><a href="n-computing.html">ncomputing</a></li> </ul> </li> <li><a href="#">printing solutions</a> <ul> <li><a href="brother.html">brother</a></li> <li><a href="epson.html">epson</a></li> </ul> </li> <li><a href="http://dealer.mustek.co.za/catalogue.html" target="_blank">complete product catalogue</a></li> </ul> </li> <li><a href="http://dealer.mustek.co.za/contact-us.html" target="_blank"><span aria-hidden="true" class="li_settings nav_icon"></span>support</a> <ul> <li><a href="http://dealer.mustek.co.za/" target="_blank">dealernet</a></li> <li><a href="dealer-application.html">dealer application form</a></li> <li><a href="dealer-locator.html">dealer locator</a></li> <li><a href="http://downloadcenter.mustek.co.za/list.php?dir=repository" target=_blank>download latest drivers</a></li> <li><a href="eyespy.html">mecer eyespy</a></li> </ul> </li> <li><a href="#"><span aria-hidden="true" class="li_phone nav_icon"></span>contact</a> <ul> <li><a href="contact.html">branches</a></li> <li><a href="mailto:customerliason@mustek.co.za?subject=general%20query%20from%20mustek%20website">customer liaison</a></li> <li><a href="mailto:ltd@mustek.co.za?subject=investor%20query%20from%20mustek%20website">investors</a></li> <li><a href="mailto:sales@mustek.co.za?subject=sales%20query%20from%20mustek%20website">sales queries</a></li> <li><a href="mailto:helpdesk@mustek.co.za?subject=query%20for%20mustek%20helpdesk">technical queries</a></li> <li><a href="http://www.pnet.co.za/#s=view_recr_jobs&g=6196" target="_blank">careers</a></li> </ul> </li> </ul> </nav> </div>
as can see class="active-page"
dictates parent icon show. read somewhere adding <?php $page = "page-name"; ?>
page , act class="active-page"
. need create id page in nav.php file reference?
sorry guys, knowledge of php limited, trying learn basics on fly. appreciated!
just use if-statement add "active-page" class current active page:
<li><a href="index.html" title="home" class="<?php if (active_page == "about") echo "active-page"; ?>"><span aria-hidden="true" class="li_display nav_icon"></span>about</a>
you need define constant active_page before including navigation.
<?php define ('active_page', "about"); include ('yournav.php'); ?>
this should work , okay if not have many pages.
an alternative in getting visited page via
$_server['php_self']
and add navigation.php html-file shall called entry in php_self. advantage have navigation-based code in 1 place. personally, prefer last solution.
Comments
Post a Comment