Hello! There was such a question. There is a menu, such as "Tariffs, reviews, send a request, about us." How can I hide the menu button of the page on which the user is now and show another? For example, if the user is on the "Tariffs" page, then do not show the tariffs button, but show for example "Special Offers"?
- What kind of urls do they have? (Doesn’t CNC?) Show your html of these buttons. - E_K
- The buttons are made in the original way) This is a picture with a link to the page - Alla
- oneYou can compare the url and the link in the button using a script, if you add a class or css style that will hide it. If the site is dynamic, then in the template to compare the page id and buttons by reference, if they match, then hide or not display it. - E_K Nov.
- and what is this script? - Alla
|
2 answers
PHP is perfect for this. Here is the code for an example:
<?php if(strstr($_SERVER['REQUEST_URI'], "restoration")){ echo <<<HTML <li><a href="#">Отзывы</a></li> <li><a href="#">Отправить заявку</a></li> <li><a href="#">О нас</a></li> HTML; } else{ echo <<<HTML <li><a href="#">Тарифы</a></li> <li><a href="#">Отзывы</a></li> <li><a href="#">Отправить заявку</a></li> <li><a href="#">О нас</a></li> HTML;} ?> In this case, for example, if the page address contains the word restoration , a menu with 3 links will be displayed, in other cases 4 links will be displayed.
Or so:
<?php $currentpage = $_SERVER['REQUEST_URI']; if($currentpage=="/index.php"){ $displaynone = "style=\"display:none\"";} ?> <li <?php echo $displaynone;?>><a href="#">Тарифы</a></li> <li><a href="#">Отзывы</a></li> <li><a href="#">Отправить заявку</a></li> <li><a href="#">О нас</a></li> In this case, if the address is index.php, then display:none will be added to the first link.
In addition, there are several other options. You can also combine these options with each other.
|
If using js, then here it is possible:
$(function() { var page = location.href.replace(/https?\:\/{2}.+\..+(\/.+)/, '$1'); if(page == '/js') $('#a').css('display', 'none'); }); <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="a">JS</div> <div id="b">Главная</div> <div id="c">О нас</div> <div id="d">Новости</div> <div id="e">Контакты</div> - those. such condition if (page == '/ js') $ ('# a'). css ('display', 'none'); Need to register for each link? I apologize if the question is stupid, I am very much a beginner in all this ( - Alla
- @Alla, yes. Well, in general, for such purposes it is done in
PHP. But if you need toJS, then like this - Yuri
|