Новости Joomla

0 Пользователей и 1 Гость просматривают эту тему.
  • 2 Ответов
  • 3465 Просмотров
*

dmitrij

  • Новичок
  • 9
  • 0 / 0
вот кусок кода в котором формируються уровни вложености категорий виртуал марта, можеть подсказать как можно для третего уровня применить совой стиль subsublevel, в нем сейчас что глубже второго уровня применяеться стиль sublevel, нужно что бы мой применялся, потому что все три уровня вложености имеют разные стили уменя

 * This function is used for the frontend to display a
      * complete link list of top-level categories
      *
      * @param int $category_id The category to be highlighted
      * @param string $links_css_class The css class that marks mainlevel links
      * @param string $list_css_class (deprecated)
      * @param string $highlighted_style The css styles that format the hightlighted category
      * @return string HTML code with the link list
      */
     function get_category_tree( $category_id=0,
                                        $links_css_class="mainlevel",
                                        $list_css_class="mm123",
                                        $highlighted_style="font-style:normal;" ) {
          global $sess;

          $categories = ps_product_category::getCategoryTreeArray();

          // Copy the Array into an Array with auto_incrementing Indexes
          $key = array_keys($categories);
          $size = sizeOf($key);
          $category_tmp = Array();
          for ($i=0; $i<$size; $i++)
          $category_tmp[$i] = &$categories[$key[$i]];

          $html = "";
          /** FIRST STEP
         * Order the Category Array and build a Tree of it
         **/
          $nrows = count( $category_tmp );

          $id_list = array();
          $row_list = array();
          $depth_list = array();

          $children = array();
          $parent_ids = array();

          for($k = 0 ; $k < $nrows ; $k++) {
               $parent_ids[$k] = $category_tmp[$k]['category_parent_id'];
          }

          for($n = 0 ; $n < $nrows ; $n++)
          if($category_tmp[$n]["category_parent_id"] == 0)
          { array_push($id_list,$category_tmp[$n]["category_child_id"]);
          array_push($row_list,$n);
          array_push($depth_list,0);
          }

          $loop_count = 0;
          while(count($id_list) < $nrows) {
               if( $loop_count > $nrows )
               break;
               $id_temp = array();
               $row_temp = array();
               $depth_temp = array();
               for($i = 0 ; $i < count($id_list) ; $i++) {
                    $id = $id_list[$i];
                    $row = $row_list[$i];
                    $depth = $depth_list[$i];
                    array_push($id_temp,$id);
                    array_push($row_temp,$row);
                    array_push($depth_temp,$depth);

                    $pattern = '/\b'.$id.'\b/';
                    $children = preg_grep( $pattern, $parent_ids );

                    foreach($children as $key => $value) {
                         if( array_search($category_tmp[$key]["category_child_id"],$id_list) == NULL) {
                              array_push($id_temp,$category_tmp[$key]["category_child_id"]);
                              array_push($row_temp,$key);
                              array_push($depth_temp,$depth + 1);
                         }
                    }
               }
               $id_list = $id_temp;
               $row_list = $row_temp;
               $depth_list = $depth_temp;
               $loop_count++;
          }

          /** SECOND STEP
          * Find out if we have subcategories to display
          **/
          $allowed_subcategories = Array();
          if( !empty( $categories[$category_id]["category_parent_id"] ) ) {
               // Find the Root Category of this category
               $root = $categories[$category_id];
               $allowed_subcategories[] = $categories[$category_id]["category_parent_id"];
               // Loop through the Tree up to the root
               while( !empty( $root["category_parent_id"] )) {
                    $allowed_subcategories[] = $categories[$root["category_child_id"]]["category_child_id"];
                    $root = $categories[$root["category_parent_id"]];
               }
          }
          // Fix the empty Array Fields
          if( $nrows < count( $row_list ) ) {
               $nrows = count( $row_list );
          }

          // Now show the categories
          for($n = 0 ; $n < $nrows ; $n++) {

               if( !isset( $row_list[$n] ) || !isset( $category_tmp[$row_list[$n]]["category_child_id"] ) )
                    continue;
               if( $category_id == $category_tmp[$row_list[$n]]["category_child_id"] )
                    $style = $highlighted_style;
               else
                    $style = "";

               $allowed = false;
               if( $depth_list[$n] > 0 ) {
                    // Subcategory!
                    if( isset( $root ) && in_array( $category_tmp[$row_list[$n]]["category_child_id"], $allowed_subcategories )
                    || $category_tmp[$row_list[$n]]["category_parent_id"] == $category_id
                    || $category_tmp[$row_list[$n]]["category_parent_id"] == @$categories[$category_id]["category_parent_id"]) {
                         $allowed = true;

                    }
               }
               
               else
                    $allowed = true;
               $append = "";
               if( $allowed ) {
                    if( $style == $highlighted_style ) {
                         $append = 'id="active_menu"';
                    }
                    if( $depth_list[$n] > 0 )
                         $css_class = "sublevel";
                         
                   
                    else
                         $css_class = $links_css_class;

                    $catname = shopMakeHtmlSafe( $category_tmp[$row_list[$n]]["category_name"] );

                    $html .= '
          <a title="'.$catname.'" style="display:block;'.$style.'" class="'. $css_class .'" href="'. $sess->url(URL."index.php?page=shop.browse&amp;category_id=".$category_tmp[$row_list[$n]]["category_child_id"]) .'" '.$append.'>'
                    . str_repeat("",$depth_list[$n]) . $catname
                    . ps_product_category::products_in_category( $category_tmp[$row_list[$n]]["category_child_id"] )
                    .'</a>';
               }
          }

          return $html;
     }
*

xxxTiTxxx

  • Осваиваюсь на форуме
  • 35
  • 6 / 0
Re: третий уровень вложености
« Ответ #1 : 25.07.2007, 18:49:34 »
Может попробовать
if( $depth_list[$n] > 0 )
                         $css_class = "sublevel";
                         
                   
                    else
                         $css_class = $links_css_class;
заменить на
if( ($depth_list[$n] > 0) AND ($depth_list[$n]!=1) ){
                         $css_class = "sublevel";
} elseif ($depth_list[$n] ==1){
          $css_class = "subsublevel";
}
                   
                    else {
                         $css_class = $links_css_class;
}

Насчет 1 не уверен попробуй еще 2 если не сработает
*

dmitrij

  • Новичок
  • 9
  • 0 / 0
Re: третий уровень вложености
« Ответ #2 : 26.07.2007, 16:35:07 »
большое спасибо заработало, но надо всётаки 2 ставить потомучто при 1 оно для второго уровня применяет subsublevel а для третего sublevel
Чтобы оставить сообщение,
Вам необходимо Войти или Зарегистрироваться