ZENCART显示二级菜单导航

来源:互联网 发布:linux界面编程 编辑:程序博客网 时间:2024/05/01 01:31

模型:

<?php

/**
 * categories_subs.php module
 *
 * @version $Id: categories_subs.php 2012-04-28 by harryxlb $
 */
if (!defined('IS_ADMIN_FLAG')) {
  die('Illegal Access');
}
$order_by = " order by c.sort_order, cd.categories_name ";

$categories_tab_query = "select c.categories_id, cd.categories_name from " .
TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd
                          where c.categories_id=cd.categories_id and c.parent_id= '0' and cd.language_id='" . (int)$_SESSION['languages_id'] . "' and c.categories_status='1'" .
$order_by;

$categories_tab = $db->Execute($categories_tab_query);

$links_list = array();
while (!$categories_tab->EOF) {
  // currently selected category
  if ((int)$cPath == $categories_tab->fields['categories_id']) {
    $new_style = 'category-top';
    $categories_tab_current = '<span class="category-subs-selected">' . $categories_tab->fields['categories_name'] . '</span>';
  } else {
    $new_style = 'category-top';
    $categories_tab_current = $categories_tab->fields['categories_name'];
  }

  // create link to top level category
      $links_list[] = '<a class="' . $new_style . '" href="' . zen_href_link(FILENAME_DEFAULT, 'cPath=' . (int)$categories_tab->fields['categories_id']) . '">' . $categories_tab_current . '</a> ';
      $links_ids[] = $categories_tab->fields['categories_id'];
                    
    //begin to get the sub categories
           $sql_subcate = "select distinct c.categories_id, cd.categories_name,c.parent_id from " .
 TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.categories_id=cd.categories_id and cd.language_id='" . (int)$_SESSION['languages_id'] . "' and c.categories_status='1' and c.parent_id = '" . $categories_tab->fields['categories_id'] . "'" .$order_by;
                              
      global $db;
      $cate_sub = $db->Execute($sql_subcate);
//      $links_subcate = array();        
      while (!$cate_sub->EOF){
          //if($cate_sub->fields['parent_id'] == $categories_tab->fields['categories_id']){
            $links_subcate[] = '<a class="subnav" href="' . zen_href_link(FILENAME_DEFAULT, 'cPath=' . (int)$cate_sub->fields['categories_id']) . '">' . $cate_sub->fields['categories_name'] . '</a> ';
//            $sublinks_ids[] = $categories_tab->fields['categories_id'];
            $sublinks_ids[] = $cate_sub->fields['parent_id'];
            $cate_sub->MoveNext();
              //}
          }
          $categories_tab->MoveNext();

}

?>


调用:


<?php
/**
 * categories_subs.php module
 *
 * @version $Id: tpl_modules_categories.php 2012-04-28 by harryxlb $
 */
 
  include(DIR_WS_MODULES . zen_get_module_directory(FILENAME_CATEGORIES_TABS));
?>
<?php if (CATEGORIES_TABS_STATUS == '1' && sizeof($links_list) >= 1) { ?>
    <div class="nav-container">
    <ul id="nav">
    <?php
            for ($i=0, $n=sizeof($links_list); $i<$n; $i++) {
//                $cate_id[$i] = $categories_tab->fields['categories_id'];
            
         ?>
         <li onmouseover="toggleMenu(this,1)" onmouseout="toggleMenu(this,0)" class="level0 nav-<?php echo $i+1;?> parent">
<span><span>
            <?php echo $links_list[$i]; ?></span></span>
           <ul class="level0">
           <!---->
            <?php
                for ($m = 0, $x = sizeof($links_subcate); $m < $x; $m++){
                   if($sublinks_ids[$m] == $links_ids[$i]){
            ?>
            <li class="level1 nav-<?php echo $i?>-<?php echo $m;?>">
                <?php echo $links_subcate[$m]; ?>
            </li>
            <?php                    
                    }
                }
            ?>
            
           </ul>

        </li>
    <?php } ?>

</ul>
</div>
<?php } ?>

    <script type="text/javascript">decorateGeneric($('nav').select('li.level0'),['first','last']);</script>
    
    
</div>



原创粉丝点击