1
ianez
mymenus 1.1 - dealing with current link highlight
  • 2011/3/18 16:42

  • ianez

  • Not too shy to talk

  • Posts: 188

  • Since: 2006/1/26


I'm testing this module for a site based on xoops 2.5 and I've had some problem using the menu (main menu basic skin) because links were not highlighted when using friendly url or in general htaccess redirect.
This was a limit due to the $menu.selected/$menu.topselected variable which is builded php side and need to be equal to the exact server request.. so if you have yoursite/module/news redirected to yoursite/articles the link won't be highlighted when your are in the page linked by menu

A working solution to me is using smarty to do the trick.. because that way even if the server request is redirected by htaccess you can have highlighted links:

in mymenus\skins\mainmenu\templates\template.html
changed in line 4
<class="menuMain <{if $menu.topselected}>maincurrent<{/if}>"

to
<a class="menuMain <{if stristr($menu.link,$smarty.server.REQUEST_URI)}>maincurrent<{/if}>"

and in line 11 from
<class="menuSub <{if $sub.selected}>maincurrent<{/if}>"

to
<class="menuSub <{if stristr($sub.link,$smarty.server.REQUEST_URI)}>maincurrent<{/if}>"


I know I could use $xoops_requesturi instead of $smarty.server.REQUEST_URI.. but in xoops 2.5 does not print anything to me, even if shown in smarty debug

May be it not 'clean' but that way I'm having current link highlighted always and without issues
probably this method can be used with all skin of the module (and may be in all templates generating menus..)
let me know your opinion

Ian

2
trabis
Re: mymenus 1.1 - dealing with current link highlight
  • 2011/3/18 19:09

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


class/builder.php
function buildSelected()
    {
        
//get the currentpage
        
$sel = array();
        
$query_string $_SERVER['QUERY_STRING'] ? '?' $_SERVER['QUERY_STRING'] : '';
        
$self 'http://' $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . $query_string;


Mymenus will not highlight the exact match, it will highlight the closest match. If $self is not holding the correct value then maybe you could find a way to fix, that would avoid touching templates and closest match would still work.

Your fix does not support closest match.

3
ianez
Re: mymenus 1.1 - dealing with current link highlight
  • 2011/3/18 19:55

  • ianez

  • Not too shy to talk

  • Posts: 188

  • Since: 2006/1/26


Hi Trabis,
I'm not a php programmer.. but to me the matching was kind of buggy and was working only if using a clean url such:
modules/news

inserting the complete urlhttp://www. mysite.com/modules/news
was not working and if there's an url rewrite I have to write the original url in the menu link field to have the match.. but this can be a contraddiction for seo purposes

I guess smarty solution don't give me problem because smarty works after php.. but this solve also asmall bug:
- when browsing in page not linked in the mymenus block, where the block is visibile I've the top link always highlighted

If there's a php solution allowing for rewrited url it would be obviously better

thanks
Ian

4
biomech
Re: mymenus 1.1 - dealing with current link highlight
  • 2013/7/30 13:56

  • biomech

  • Not too shy to talk

  • Posts: 161

  • Since: 2002/2/25


Hi guys,

I'm using MyMenus 1.1 and XOOPS 2.5.6. I can't figure out how to get the current page link to highlight. I've tried setting CSS info in the links, but it has no effect on the appearance of the menu - no highlighting. I tried the hack that ianez showed below, but nothing changes.

Any ideas?

Cheers,

- b -

Login

Who's Online

166 user(s) are online (101 user(s) are browsing Support Forums)


Members: 0


Guests: 166


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Apr 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits