antoinedan Posted October 11, 2013 Share Posted October 11, 2013 Hi! In the module blocktopmenu i need the class active. I test this code but not function. What can I do? Thanks! case 'LNK': $selected = ($link->getPageLink == $page_name ) ? ' class="sfHover"' : ''; $link = MenuTopLinks::get((int)$id, (int)$id_lang, (int)$id_shop); if (count($link)) { if (!isset($link[0]['label']) || ($link[0]['label'] == '')) { $default_language = Configuration::get('PS_LANG_DEFAULT'); $link = MenuTopLinks::get($link[0]['id_linksmenutop'], $default_language, (int)Shop::getContextShopID()); } $this->_menu .= '<li'.$selected.' ><a href="'.$link[0]['link'].'"'.(($link[0]['new_window']) ? ' target="_blank"': '').'>'.$link[0]['label'].'</a></li>'.PHP_EOL; } break; Link to comment Share on other sites More sharing options...
vekia Posted October 11, 2013 Share Posted October 11, 2013 hello what you mean by: Hi! In the module blocktopmenu i need the class active. you want to add class="active" ? if so, whevere? for what element exactly? Link to comment Share on other sites More sharing options...
antoinedan Posted October 11, 2013 Author Share Posted October 11, 2013 In the horizontal menu ("blocktopmenu"), i want when i click on a link (for example 'index' or 'new products'), this link become class="selected". It works for the link category and cms but not for the normal links in the menu. Link to comment Share on other sites More sharing options...
skywhi Posted October 12, 2013 Share Posted October 12, 2013 I have the same problem! My links "index", "new-products" and "prices-drop" aren't "class="sfHoverForce" when i'm on the page but the others (products category and cms) are "class="sfHoverForce" when i click on. If someone has a solution for that, it would be awesome! Link to comment Share on other sites More sharing options...
antoinedan Posted October 13, 2013 Author Share Posted October 13, 2013 Nobody have an idea for resolve my problematic about the links of the top menu? Many days i'm block on this. Thank you in advance! Link to comment Share on other sites More sharing options...
vekia Posted October 13, 2013 Share Posted October 13, 2013 you need to edit code for each kind of page. but the question is: how you added links to top horizontal menu to: new products, prices drop etc. im asking because by default there is no possibility to add these links there (a part of "left" box from module configurataion page) as you can see there is no option to add these links Link to comment Share on other sites More sharing options...
antoinedan Posted October 13, 2013 Author Share Posted October 13, 2013 (edited) I add this links with the option "Add a link" under the printscreen you watch me. Edited October 13, 2013 by antoinedan (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted October 13, 2013 Share Posted October 13, 2013 well, in this case is almost impossible to achieve what you expect. If I were you I will create these links manually, then it will be much easier to achieve it. <li class="'.($this->context->smarty->tpl_vars['page_name']->value=="new-products" ? 'selected':'').'"><a href="'.$link->getPageLink('new-products').'">New products</a></li> add this link (and any other link you want) to $this->_menu .= Link to comment Share on other sites More sharing options...
antoinedan Posted October 13, 2013 Author Share Posted October 13, 2013 Your solution not works, so i've add this on blocktopmenu.tpl: <li {if $page_name == 'new-products'} class="sfHoverForce"{/if}><a href="{$link->getPageLink('new-products')}">{l s='Nouveautés'}</a></li> <li {if $page_name == 'index'} class="sfHoverForce"{/if}><a href="{$link->getPageLink('index')}">{l s='Accueil'}</a></li> <li {if $page_name == 'prices-drop'} class="sfHoverForce"{/if}><a href="{$link->getPageLink('prices-drop')}">{l s='Promotions'}</a></li> The links appear but when i click on one of them, this is the link "Index" who is always in class="sfhoverForce". The two others not. Why? Link to comment Share on other sites More sharing options...
gonebdg - webindoshop.com Posted October 14, 2013 Share Posted October 14, 2013 Default blocktopmenu module, will add class="sfHover" to selected/activated menu. Do you have another reason why you wanna add class="active" ? Link to comment Share on other sites More sharing options...
vekia Posted October 14, 2013 Share Posted October 14, 2013 you're talking about "hover" effect, and we are talking here about "active" page. it mean something like if you're in "iPods" category - then in top menu iPods menu item has got "active" class. In this case it is easy to achieve. but for links defined manually it isn't Link to comment Share on other sites More sharing options...
gonebdg - webindoshop.com Posted October 14, 2013 Share Posted October 14, 2013 I see ...The easy way is using get variable.It mean you should add an unique id for each custom link that you add to the blocktopmenu, e.g: ?id_lnk=xIf your original link was ./myCustomLink , then you should type it like this ./myCustomLink?id_lnk=xwhere x = your unique id (can be a number) Then you can modify the blocktopmenu module core file like this : case 'LNK': $link = MenuTopLinks::get((int)$id, (int)$id_lang, (int)$id_shop); if (count($link)) { if (!isset($link[0]['label']) || ($link[0]['label'] == '')) { $default_language = Configuration::get('PS_LANG_DEFAULT'); $link = MenuTopLinks::get($link[0]['id_linksmenutop'], $default_language, (int)Shop::getContextShopID()); } // start-modification $id_lnk = Tools::getValue('id_lnk'); $part = explode('?id_lnk=', htmlentities($link[0]['link'])); $selected = (isset($id_lnk) && isset($part[1]) && $id_lnk == $part[1]) ? ' class="actived"' : ''; // end-modification $this->_menu .= '<li'.$selected.'><a href="'.htmlentities($link[0]['link']).'"'.(($link[0]['new_window']) ? ' target="_blank"': '').'>'.$link[0]['label'].'</a></li>'.PHP_EOL; } break; Note: Don't forget to clear smarty cache Link to comment Share on other sites More sharing options...
Dublay Posted October 21, 2013 Share Posted October 21, 2013 Hi, is it possible to add a class-name to every link? Actually its <li class=""> Thanks! Link to comment Share on other sites More sharing options...
NemoPS Posted October 21, 2013 Share Posted October 21, 2013 Yes, you can, by editing the makeMenu() method of blocktopmenu.php, and the sub-methods it uses to build the tree structure Link to comment Share on other sites More sharing options...
Dublay Posted October 21, 2013 Share Posted October 21, 2013 (edited) Yes, you can, by editing the makeMenu() method of blocktopmenu.php, and the sub-methods it uses to build the tree structure Got it - thanks! <li id="nav_'.$cms[0]['meta_title'].'">... Is this correct? Or is there a better variable to use for this? Edited October 21, 2013 by Dublay (see edit history) Link to comment Share on other sites More sharing options...
Dublay Posted October 21, 2013 Share Posted October 21, 2013 I think this isn't working for me. Can anyone help out and tell me how to get a 'unique' class for every link? Link to comment Share on other sites More sharing options...
gonebdg - webindoshop.com Posted October 21, 2013 Share Posted October 21, 2013 I think this isn't working for me. Can anyone help out and tell me how to get a 'unique' class for every link? What do you mean about 'unique' class ? to specify a style for a single/unique element you should use id instead class as the css selector Link to comment Share on other sites More sharing options...
Dublay Posted October 22, 2013 Share Posted October 22, 2013 ID would be the better choice, so I need something like this in the menu: <li id="welcome">...</li> <li id="shop">...</li> <li id="contact">...</li> or maybe <li id="id_1">...</li> <li id="id_2">...</li> Any idea how to archive this in the blocktopmenu.php? Link to comment Share on other sites More sharing options...
vekia Posted October 22, 2013 Share Posted October 22, 2013 and what about simple js script like: $(document).ready(function() { for (var i=0; i <= 9; i++) { $(".sf-menu > li:nth-child(" + i + ")").attr("id","menu_" + i); } }); Link to comment Share on other sites More sharing options...
Dublay Posted October 22, 2013 Share Posted October 22, 2013 and what about simple js script like: $(document).ready(function() { for (var i=0; i <= 9; i++) { $(".sf-menu > li:nth-child(" + i + ")").attr("id","menu_" + i); } }); Because this isn't really unique - when i.e. adding an extra cms-page to the project, I've to update it manually. Isn't it possible to add the page name as a unique id? Or the page ID as css-ID? Link to comment Share on other sites More sharing options...
vekia Posted October 22, 2013 Share Posted October 22, 2013 only with modifications of the module core. there is a lot to do in this case because each part of the store has got own code in switch function. Link to comment Share on other sites More sharing options...
gonebdg - webindoshop.com Posted October 28, 2013 Share Posted October 28, 2013 ID would be the better choice, so I need something like this in the menu: <li id="welcome">...</li> <li id="shop">...</li> <li id="contact">...</li> or maybe <li id="id_1">...</li> <li id="id_2">...</li> Any idea how to archive this in the blocktopmenu.php? what is the goal of this modification ? Link to comment Share on other sites More sharing options...
antoniocici Posted November 16, 2014 Share Posted November 16, 2014 After reading your proposal, I've made some modifications to the makeMenu() function of the blocktopmenu module class as follow: case 'LNK': $link = MenuTopLinks::get((int)$id, (int)$id_lang, (int)$id_shop); if (count($link)) { if (!isset($link[0]['label']) || ($link[0]['label'] == '')) { $default_language = Configuration::get('PS_LANG_DEFAULT'); $link = MenuTopLinks::get($link[0]['id_linksmenutop'], $default_language, (int)Shop::getContextShopID()); } //start mod $current = explode('?', Tools::safeOutput(urldecode($_SERVER['REQUEST_URI']))); $selected = (Tools::HtmlEntitiesUTF8($link[0]['link']) == $current[0]) ? ' class="sfHover"' : ''; $this->_menu .= '<li'.$selected.'><a href="'.Tools::HtmlEntitiesUTF8($link[0]['link']).'"'.(($link[0]['new_window']) ? ' onclick="return !window.open(this.href);"': '').' title="'.Tools::safeOutput($link[0]['label']).'">'.Tools::safeOutput($link[0]['label']).'</a></li>'.PHP_EOL; // end mod } break; I've simply parsed the request uri contained into the $_SERVER var and compared it with the link saved into the menu. It works great and may be helpful for others. Link to comment Share on other sites More sharing options...
Elfiszcze Posted June 10, 2015 Share Posted June 10, 2015 I need to add class to every first level top menu element. and what about simple js script like: $(document).ready(function() { for (var i=0; i <= 9; i++) { $(".sf-menu > li:nth-child(" + i + ")").attr("id","menu_" + i); } }); Will it work in 1.6.0.14? Where exactly I should put this code? Link to comment Share on other sites More sharing options...
jucedupp Posted September 24, 2015 Share Posted September 24, 2015 (edited) For Prestashop 1.6.1.0: makeMenu() function in the blocktopmenu module (blocktopmenu.php): case 'LNK': $link = MenuTopLinks::get((int)$id, (int)$id_lang, (int)$id_shop); if (count($link)) { if (!isset($link[0]['label']) || ($link[0]['label'] == '')) { $default_language = Configuration::get('PS_LANG_DEFAULT'); $link = MenuTopLinks::get($link[0]['id_linksmenutop'], $default_language, (int)Shop::getContextShopID()); } $current = explode('?', Tools::safeOutput(urldecode($_SERVER['REQUEST_URI']))); $selected = (Tools::HtmlEntitiesUTF8($link[0]['link']) == $current[0]) ? ' class="sfHoverForce"' : ''; $this->_menu .= '<li'.$selected.'><a href="'.Tools::HtmlEntitiesUTF8($link[0]['link']).'"'.(($link[0]['new_window']) ? ' onclick="return !window.open(this.href);"': '').' title="'.Tools::safeOutput($link[0]['label']).'">'.Tools::safeOutput($link[0]['label']).'</a></li>'.PHP_EOL; } break; in themes\default-bootstrap\css\modules\blocktopmenu\css\superfish-modified.css: I made the following modification: .sf-menu > li.sfHoverForce > a{ background-color: white; color: #000 !important; text-shadow: none; } I would recommend you do a module override for this by placing blocktopmenu.php in in themes\default-bootstrap\modules\blocktopmenu\ otherwise you are going to lose your changes next time you update the module. J Edited September 24, 2015 by jucedupp (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now