KalashaLv Posted May 29, 2017 Report Share Posted May 29, 2017 Heyy, ir kaut kādā vedā iespējams pievienot class="active"? Lūk navigation : <nav> <ul> <li><a href="<?=$url;?>">Sākums</a></li> <li><a href="<?=$url;?>/forums">Forums</a></li> <li><a <?php if(isset($_GET['stats'])) { echo " class=\"active\""; } ?> href="#">Stati</a></li> <li><a <?php if(isset($_GET['bans'])) { echo " class=\"active\""; } ?> href="#">Bani</a></li> <li><a <?php if(isset($_GET['shop'])) { echo " class=\"active\""; } ?> href="#">Veikals</a></li> <li><a <?php if(isset($_GET['contacts'])) { echo " class=\"active\""; } ?> href="<?=$url;?>?contacts">Kontakti</a></li> </ul> </nav> lūk kur izlasa lapas : if(isset($_GET['poll'])) { $link = 'admin/add-poll.php'; $vieta = "poll"; $title = "Aptaujas labošana";} else if(isset($_GET['admin'])) {$link = 'admin/admin.php'; $title = 'Admina kontroles panelis'; $vieta = "admin";} else if(isset($_GET['add_img'])) {$link = 'admin/add-img.php'; $title = 'Pievienot jaunumu bildi'; $vieta = "add_img";} else if(isset($_GET['add_ban'])) {$link = 'includes/bans.php'; $title = Bani'; $vieta = "bans";} else if(isset($_GET['contacts'])) {$link = 'includes/contacts.php'; $title = 'Kontakti'; $vieta = "contacts";} else if(isset($_GET['contacts'])) {$link = 'includes/stats.php'; $title = 'Stati'; $vieta = "stats";} else { $link = 'includes/news.php'; $vieta = "news"; $title = "Jaunumi";} vietās, kur, navigācijā, ir <?php if(isset($_GET['contacts'])) { echo " class=\"active\""; } ?> tur iet, bet man vajag pivienot, lai rāda "active" Sākumlapā, jo ar to pašu metodi nedarbojas, jo na var $_GET Quote Link to comment Share on other sites More sharing options...
briedis Posted May 29, 2017 Report Share Posted May 29, 2017 Kas tev īsti nestrādā? Quote Link to comment Share on other sites More sharing options...
Faks Posted May 29, 2017 Report Share Posted May 29, 2017 var jau bazisku jquery lai liek active ^^ Quote Link to comment Share on other sites More sharing options...
Faks Posted May 29, 2017 Report Share Posted May 29, 2017 (edited) pat ar js var... var url = window.location; $('ul.nav a[href="'+ url +'"]').parent().addClass('active'); $('ul.nav a').filter(function() { return this.href == url; }).parent().addClass('active'); ka ir ertak js vai jquery bez starpibas ... jo padoma rakstisi 10 if del vienas ficas ja var sadi ? jo realitate jataisa check kads links ir aktivs un tad tikai zagejam klat aktivo tatad jaraksta vainu funkcija vai class bet kada joka pec ja var isak atrak un vienkarsak ? Edited May 29, 2017 by Faks korekcija Quote Link to comment Share on other sites More sharing options...
zeCode Posted May 29, 2017 Report Share Posted May 29, 2017 (edited) Vel jau sadaļa Stati / Bani / Veikals satur vienādu linku ... ... href="<?php echo $url. '/bans'; ?>">Bani</a></li> $menus = [ 'Sākums' => '' , 'Forums' => 'forums' , 'Stati' => 'stati' , 'Bani' => 'bans' , 'Veikals' => 'shop' , 'Kontakti' => 'contacts' ]; $urlArray = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); $segments = explode('/', $urlArray); $segment_numb = 1; $html = ''; foreach ($menus as $menu_name => $menu_link) { $link_class = (( strtolower($segments[$segment_numb]) == strtolower($menu_link)) || (!$segments[$segment_numb] && !$html) ) ? 'active' : ''; $html .= '<li><a href="' . $url . ( $menu_link ? '/' . $menu_link : '' ) . '" class="' . $link_class . '">' . $menu_name . '</a></li>'; } echo '<nav><ul>' . $html . '</ul></nav>'; Edited May 29, 2017 by zeCode Quote Link to comment 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.