Advertisement
Mihalytch

Untitled

May 23rd, 2013
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.13 KB | None | 0 0
  1. <nav class="menu-widget">
  2.  
  3.     <ul>
  4.     <?php
  5.     if(isset($categories)) {
  6.         $prevLevel = 1;
  7.         $i=0;
  8.        
  9.         foreach ($categories as $category) {
  10.             $level = $category->level;
  11.            
  12.             $prefix = '</li>'."\n";
  13.             if($i==0) $prefix = '';
  14.            
  15.             $sufix  = '';
  16.            
  17.             if($level>$prevLevel) {
  18.                 $prefix = "\n".'<ul>'."\n";
  19.             } else if($level<$prevLevel) {
  20.                 $prefix .= '</ul>'."\n".'</li>'."\n";
  21.             }
  22.            
  23.             if($category->parent_id == 0) {
  24.                 //$href = '/section'.$category->id;
  25.                 $href = Yii::app()->createUrl(
  26.                             'page/list',
  27.                             array(
  28.                                 'section'=>$category->id
  29.                             )
  30.                         );
  31.             } else {
  32.                 //$href = '/section'.$category->parent_id.'/subsection'.$category->id;
  33.                 $href = Yii::app()->createUrl(
  34.                             'page/list',
  35.                             array(
  36.                                 'section' => $category->parent_id,
  37.                                 'subsection' => $category->id,
  38.                             )
  39.                         );
  40.             }
  41.            
  42.             echo $prefix.'<li><a href="'. Yii::app()->baseUrl . $href .'">'.$category->name.'</a>'.$sufix;
  43.            
  44.            
  45.             $prevLevel = $level;
  46.             $i++;
  47.         }
  48.        
  49.         if($level>1) {
  50.             $level -= 1;
  51.             while($level--) { echo '</li></ul>'; }
  52.         }
  53.     }
  54.    
  55.     ?>
  56.        
  57.     </ul>
  58. </nav>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement