can someone help me with horizontal menu? I want make acive page on this menu, I thing i need add new class to css file. I hope u understand me. Thanks
This is what i have now: menu-theme2.css
<ul class="theme2">
<li><a href="index.php"><span>HOME</span></a></li>
<li><a href="kredity.php"><span>KREDITY</span></a></li>
<li><a href="shop.php"><span>SHOP</span></a></li>
<li><a href="aukce.php"><span>AUKCE</span></a></li>
<li><a href="servery.php"><span>SERVERY</span></a>
<li><a href="forum"><span>FORUM</span></a></li>
</ul>
And i want this on index.php:
<ul class="theme2">
<li><a class="active" href="index.php"><span>HOME</span></a></li>
<li><a href="kredity.php"><span>KREDITY</span></a></li>
<li><a href="shop.php"><span>SHOP</span></a></li>
<li><a href="aukce.php"><span>AUKCE</span></a></li>
<li><a href="servery.php"><span>SERVERY</span></a>
<li><a href="forum"><span>FORUM</span></a></li>
</ul>
Try to something like this.
For horizontal menu you can put below css rules in your css file.
.theme2 li {
float: left;
list-style: outside none none;
margin-left: 10px;
}
For active class.
$(function(){
var url = window.location.pathname;
alert(url);
urlRegExp = new RegExp(url.replace(/\/$/,'') + "$");
// create regexp to match current url pathname and remove trailing slash if present as it could collide with the link in navigation in case trailing slash wasn't present there
// now grab every link from the navigation
$('.theme2 ul li a').each(function(){
// and test its normalized href against the url pathname regexp
if(urlRegExp.test(this.href.replace(/\/$/,''))){
$(this).addClass('active');
}
});
});
index.php
<?php $page = "index"; ?>
shop.php
<?php $page = "shop"; ?>
<ul>
<li><a <?php if($page == 'index') {echo 'class="active"';} ?> href="index.php"><span>HOME</span></a></li>
<li><a <?php if($page == 'shop') {echo 'class="active"';} ?> href="index.php"><span>SHOP</span></a></li>
</ul>
Following Nikit's solution, you can do the following without setting the $page
variable value in each page, using PHP's __FILE__
constant:
<ul>
<li><a <?php if(basename(__FILE__, '.php') == 'index') {echo 'class="active"';} ?> href="index.php"><span>HOME</span></a></li>
<li><a <?php if(basename(__FILE__, '.php')== 'shop') {echo 'class="active"';} ?> href="index.php"><span>SHOP</span></a></li>
</ul>