Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.

Bug report: selection of sub navigation

+1 vote
896 views
asked Nov 25, 2014 in Q2A Core by sama55

I found a small bug.

Phenomenon:

Sub navigation with short URL than access URL is selected.

Example of OK case:

Sub nav1: http://example.com/mainnavi/sub1
Sub nav2: http://example.com/mainnavi/sub2

Example of NG case:

Sub nav1: http://example.com/mainnavi/sub
Sub nav2: http://example.com/mainnavi/sub2

When sub2 is accessed, sub is also selected.

Solution for V1.6:

qa-include/qa-page.php (around L245)

Before:

foreach ($qa_content['navigation'] as $navtype => $navigation)
  if (is_array($navigation) && ($navtype!='cat'))
    foreach ($navigation as $navprefix => $navlink)
      if (substr($requestlower.'$', 0, strlen($navprefix)) == $navprefix)
        $qa_content['navigation'][$navtype][$navprefix]['selected']=true;

After:

foreach ($qa_content['navigation'] as $navtype => $navigation) {
  if (is_array($navigation) && ($navtype!='cat')) {
    foreach ($navigation as $navprefix => $navlink) {
      if(strlen($navprefix) > strlen($requestlower))
        $len = strlen($navprefix);
      else
        $len = strlen($requestlower);
      if (substr($requestlower.'$', 0, $len) == $navprefix) {
        $qa_content['navigation'][$navtype][$navprefix]['selected']=true;
      }
    }
  }
}
Q2A version: 1.6 later
commented Nov 26, 2014 by sama55
This issue has been discussed here.
https://github.com/q2a/question2answer/issues/152
commented Nov 28, 2014 by sama55
Scott fixed this issue. This changes will be reflected in next version.
https://github.com/q2a/question2answer/issues/152

1 Answer

+3 votes
answered Dec 9, 2014 by Scott
Just answering this to say that the issue is now fixed in 1.7-beta2.
...