Icebergness Posted January 12, 2012 Share Posted January 12, 2012 Hi, I realise there is likely a very simple solution to this, but I'm pulling my hair out on it. I have a menu.php file on my Intranet that (funnily enough) holds the site menu and is inserted via an include. This works fine. My question is, how can I make it pick up what page I am on in the site, and change the menu accordingly? At the moment, with HTML (and before I changed the site to hold just one menu file), the menu looked like this: <li class="link"> <a class="link levela" title="The drive formally known as "P""> <span>Company Documents</span></a> <ul> <li class="link"> <a class="link levelb" href="http://hhnet/company_documents/comm_forms.php" title="Forms... for Commission"> <span>Commission Forms</span></a></li> <li class="link"> <a class="link levelb" href="http://hhnet/company_documents/complaint_documentation.php" title="Documents documenting complaints."> <span>Complaint Documentation</span></a></li> and when the page was the current one, it looked like this: <li class="current"> <a class="current levela" title="The drive formally known as "P""> <span>Company Documents</span></a> <ul> <li class="current"> <a class="current levelb" href="http://hhnet/company_documents/comm_forms.php" title="Forms... for Commission"> <span>Commission Forms</span></a></li> <li class="link"> <a class="link levelb" href="http://hhnet/company_documents/complaint_documentation.php" title="Documents documenting complaints."> <span>Complaint Documentation</span></a></li> As you can see, the class changes to "current". I want to be able to do it so that the central menu file can pick up what page the user is on, and mark the class as current. Any suggestions? Dave Quote Link to comment https://forums.phpfreaks.com/topic/254878-help-with-php-menu/ Share on other sites More sharing options...
dharmeshpat Posted January 12, 2012 Share Posted January 12, 2012 put this code above ur php include file name menu.php <?php $path = $_SERVER['SCRIPT_NAME']; $script = explode("/", $path); $filename = explode(".", $script[sizeof($script) - 1]); ?> Quote Link to comment https://forums.phpfreaks.com/topic/254878-help-with-php-menu/#findComment-1306867 Share on other sites More sharing options...
dharmeshpat Posted January 12, 2012 Share Posted January 12, 2012 <?php $path = $_SERVER['SCRIPT_NAME']; $script = explode("/", $path); $filename = explode(".", $script[sizeof($script) - 1]); ?> <li class="link"> <a class="link levela" title="The drive formally known as "P""> <span>Company Documents</span></a> <ul> <li class="link"> <a class="<?php if ($filename[0] == "comm_forms") { echo "current"; }else{ echo "link"; } ?> levelb" href="http://hhnet/company_documents/comm_forms.php" title="Forms... for Commission"> <span>Commission Forms</span></a></li> <li class="link"> <a class="<?php if ($filename[0] == "complaint_documentation") { echo "current"; }else{ echo "link"; } ?> levelb" href="http://hhnet/company_documents/complaint_documentation.php" title="Documents documenting complaints."> <span>Complaint Documentation</span></a></li> Quote Link to comment https://forums.phpfreaks.com/topic/254878-help-with-php-menu/#findComment-1306868 Share on other sites More sharing options...
Muddy_Funster Posted January 12, 2012 Share Posted January 12, 2012 that's really not the best way to do it, you are going to have a hell of a time maintaining that. Quote Link to comment https://forums.phpfreaks.com/topic/254878-help-with-php-menu/#findComment-1306875 Share on other sites More sharing options...
dharmeshpat Posted January 12, 2012 Share Posted January 12, 2012 i do know that but it would be great help i you can tell us the best and most suitable way to achieve the result Rather than pointing the fingers on others Quote Link to comment https://forums.phpfreaks.com/topic/254878-help-with-php-menu/#findComment-1306878 Share on other sites More sharing options...
Muddy_Funster Posted January 12, 2012 Share Posted January 12, 2012 I would need to see the code for index.php, menu.php, and a sample content page to provide that level of information. It will also likely requre a significant re-write of the code, not something that can be posted up in a hurry. If the OP is prepared to provide the affore mentioned code I will happily have a look at what can be done. Quote Link to comment https://forums.phpfreaks.com/topic/254878-help-with-php-menu/#findComment-1306883 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.