brown2005 Posted May 28, 2009 Share Posted May 28, 2009 hi i have a class .active { } and the menu <ul> <li class='active'>Home<li> <li>Page1<li> <li>Page2<li> </ul> When I select a new page how can I chagne the active part to the appropiate page? Thanks in advance Link to comment https://forums.phpfreaks.com/topic/160015-active-page-inc-class/ Share on other sites More sharing options...
anupamsaha Posted May 28, 2009 Share Posted May 28, 2009 hi i have a class .active { } and the menu <ul> <li class='active'>Home<li> <li>Page1<li> <li>Page2<li> </ul> Thanks in advance Can you please provide some more information here? Link to comment https://forums.phpfreaks.com/topic/160015-active-page-inc-class/#findComment-844091 Share on other sites More sharing options...
brown2005 Posted May 28, 2009 Author Share Posted May 28, 2009 what i mean is at the start the menu will be... <ul> <li class='active'>Home<li> <li>Page1<li> <li>Page2<li> </ul> if i click on page1 then it will be <ul> <li>Home<li> <li class='active'>Page1<li> <li>Page2<li> </ul> and so on.... what I want to know is; what can I do to automatically remove the class from one page and put it onto another, when the page is selected. Link to comment https://forums.phpfreaks.com/topic/160015-active-page-inc-class/#findComment-844094 Share on other sites More sharing options...
Dathremar Posted May 28, 2009 Share Posted May 28, 2009 Put id on that <li> tags and then use Java Script to put the "active" class on your selected link. For the java script part: document.getelementbyid(id_changed).className = newClass; document.getelementbyid(id_previous).className = ""; // or some other class Also another option is if You reload the page do that with php. Link to comment https://forums.phpfreaks.com/topic/160015-active-page-inc-class/#findComment-844104 Share on other sites More sharing options...
anupamsaha Posted May 28, 2009 Share Posted May 28, 2009 Here is the concept in pure PHP. Please try this. commonInclude.php <?php /** * commonInclude.php */ // List of pages $pageArray = array( 'home', 'page1', 'page2', ); function getLink($pageIndex = 0) { global $pageArray; $returnLinks = array(); // Print the starting UL print '<ul>'; // If the pageIndex passed to the function does not exist in $pageArray, take the home as default if ( !isset($pageArray[$pageIndex]) ) { $default = 0; } // Else, default is the pageName passed in this function else { $default = $pageIndex; } // Construct all the LI tags here for($index = 0, $count = sizeof($pageArray); $index < $count; $index++) { if ( $index == $default ) { print '<li class="active">' . $pageArray[$index] . '</li>'; } else { print '<li>' . $pageArray[$index] . '</li>'; } } // Print the closing UL print '</ul>'; } ?> home.php <?php include_once('commonInclude.php'); // The menu section getLink(0); ?> page1.php <?php include_once('commonInclude.php'); // The menu section getLink(1); ?> And so on.... Does it make sense? Link to comment https://forums.phpfreaks.com/topic/160015-active-page-inc-class/#findComment-844114 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.