自定义导航如何增加currentPage???

2016-07-07 14:55 来源:www.chinab4c.com 作者:ecshop专家

大家好,有没有人知道添加自定义导航如何实现currentpage,实现菜单栏选中效果???

或者如何在“自定义导航栏”里增加单个商品、单篇文章或专题等内容???

谢谢~!~!~!

回答:
在“自定义导航栏”的系统内容里增加单个商品、单篇文章或专题等内容???

看懂这个函数就知道怎么回事了?
  1. /**
  2. * 取得自定义导航栏列表
  3. * @paramstring$type 位置,如top、bottom、middle
  4. * @returnarray列表
  5. */
  6. function get_navigator($ctype = '', $catlist = array())
  7. {
  8. $sql = 'SELECT * FROM '. $GLOBALS['ecs']->table('nav') . '
  9. WHERE ifshow = \'1\' ORDER BY type, vieworder';
  10. $res = $GLOBALS['db']->query($sql);

  11. $cur_url = substr(strrchr($_SERVER['REQUEST_URI'],'/'),1);

  12. if (intval($GLOBALS['_CFG']['rewrite']))
  13. {
  14. if(strpos($cur_url, '-'))
  15. {
  16. preg_match('/([a-z]*)-([0-9]*)/',$cur_url,$matches);
  17. $cur_url = $matches[1].'.php?id='.$matches[2];
  18. }
  19. }
  20. else
  21. {
  22. $cur_url = substr(strrchr($_SERVER['REQUEST_URI'],'/'),1);
  23. }

  24. $noindex = false;
  25. $active = 0;
  26. $navlist = array(
  27. 'top' => array(),
  28. 'middle' => array(),
  29. 'bottom' => array()
  30. );
  31. while ($row = $GLOBALS['db']->fetchRow($res))
  32. {
  33. $navlist[$row['type']][] = array(
  34. 'name'=>$row['name'],
  35. 'opennew'=>$row['opennew'],
  36. 'url' =>$row['url'],
  37. 'ctype'=>$row['ctype'],
  38. 'cid' =>$row['cid'],
  39. );
  40. }

  41. /*遍历自定义是否存在currentPage*/
  42. foreach($navlist['middle'] as $k=>$v)
  43. {
  44. $condition = empty($ctype) ? (strpos($cur_url, $v['url']) === 0) : (strpos($cur_url, $v['url']) === 0 && strlen($cur_url) == strlen($v['url']));
  45. if ($condition)
  46. {
  47. $navlist['middle'][$k]['active'] = 1;
  48. $noindex = true;
  49. $active += 1;
  50. }
  51. }

  52. if(!empty($ctype) && $active < 1)
  53. {
  54. foreach($catlist as $key => $val)
  55. {
  56. foreach($navlist['middle'] as $k=>$v)
  57. {
  58. if(!empty($v['ctype']) && $v['ctype'] == $ctype && $v['cid'] == $val && $active < 1)
  59. {
  60. $navlist['middle'][$k]['active'] = 1;
  61. $noindex = true;
  62. $active += 1;
  63. }
  64. }
  65. }
  66. }

  67. if ($noindex == false) {
  68. $navlist['config']['index'] = 1;
  69. }

  70. return $navlist;
  71. }
复制代码