Введите часть искомого слова, названия или фразы...
↑ ↓
  1. Новые темы озаглавленные с маленькой буквы - удаляются без предупреждения!
  2. Вопрос без рабочей ссылки на проблему считается риторическим. Без ссылки и скриншота - провокацией!

Помогите с сортировкой

Тема в разделе "Вопросы новичков", создана пользователем sslion, 11 янв 2018.

  1. sslion

    sslion

    Сообщения:
    9
    Симпатии:
    1
    Баллы:
    3
    Есть задача отсортировать вывод названий подкатегорий в алфовитном порядке.
    В консоли методом перетаскивания этих подкатегорий я выставил как надо, но на сайте никакого эффекта. Может дело в самом скрипте, который выводит эти "плашки" на экран?
    [​IMG]
    Вот код который выводит "плашки"
    PHP:
    <div class="cat-row">
                <div class="container cf">
                    <div class="cat-row__buttons"><a href="#" id="dlya-detej" class="cat-row__button active"><?php $term get_term(7,"product_cat"); echo $term->name;?></a><a href="#" id="dlya-mam" class="cat-row__button"><?php $term get_term(113,"product_cat"); echo $term->name;?></a></div>
                    <?php
                    $taxonomy 
    "product_cat";
                    
    /** Get all taxonomy terms */
                    
    $terms get_terms($taxonomy, array(
                            
    "orderby"    => "name"// здесь вместо "name" было "count"
                            
    "order"    => "ASC",  // "oder"  я добавил сам
                            
    "hide_empty" => false
                        
    )
                    );
                    
    $hierarchy _get_term_hierarchy($taxonomy);
                    foreach(
    $terms as $term)
                    {
                        if(
    $term->parent)
                        {
                          continue;
                        }
                        if(
    $hierarchy[$term->term_id])
                        {
                          if(
    $term->slug == "dlya-detej")
                          {
                            
    ?>
                              <ul class="cat-row__list active">
                            <?php
                          
    }
                          if(
    $term->slug == "dlya-mam")
                          {
                            
    ?>
                              <ul class="cat-row__list mom__list">
                            <?php
                          
    }

                          foreach(
    $hierarchy[$term->term_id] as $child)
                          {

                            
    $child get_term($child"product_cat");

                            switch (
    $child->slug) {
                              case 
    'podguzniki':
                                
    ?><li class="menu-item-has-children podguznik"><i></i><?php
                                
    break;
                              case 
    'mnogorazovaya-produktsiya-gloryes':
                                
    ?><li class="menu-item-has-children gloryes"><i></i><?php
                                
    break;
                              case 
    'detskoe-pitanie':
                                
    ?><li class="menu-item-has-children detskoe-pitanie"><i></i><?php
                                
    break;
                              case 
    'aksessuary-dlya-kormleniya':
                                
    ?><li class="menu-item-has-children aksesuari"><i></i><?php
                                
    break;
                              case 
    'gigiena-i-uhod':
                                
    ?><li class="menu-item-has-children gigiena"><i></i><?php
                                
    break;
                              case 
    'prorezyvateli-i-pustyshki':
                                
    ?><li class="menu-item-has-children pustishka"><i></i><?php
                                
    break;
                              case 
    'bytovaya-himiya':
                                
    ?><li class="menu-item-has-children ximia"><i></i><?php
                                
    break;
                              case 
    'detskaya-odezhda':
                                
    ?><li class="menu-item-has-children odejda"><i></i><?php
                                
    break;
                              case 
    'belyo-dlya-beremennyh-i-kormyashhih':
                                
    ?><li class="menu-item-has-children berem"><i></i><?php
                                
    break;
                              case 
    'aksessuary-dlya-kormleniya-dlya-mam':
                                
    ?><li class="menu-item-has-children aksesuar"><i></i><?php
                                
    break;
                              case 
    'produkty-dlya-laktatsii':
                                
    ?><li class="menu-item-has-children laktacia"><i></i><?php
                                
    break;
                              case 
    'sbory-v-roddom':
                                
    ?><li class="menu-item-has-children sbory"><i></i><?php
                                
    break;
                              case 
    'igrushki':
                                
    ?><li class="menu-item-has-children igrushki"><i></i><?php
                                
    break;
                              case 
    'kosmetika-aksessuary-dlya-kormleniya-dlya-mam':
                                
    ?><li class="menu-item-has-children kosmetika"><i></i><?php
                                
    break;
                              case 
    'slingi':
                                
    ?><li class="menu-item-has-children slingi"><i></i><?php
                                
    break;
                              default:
                                
    ?><li class="menu-item-has-children laktacia"><i></i><?php
                                
    break;
                            }

                            
    $term_link get_term_link($child->term_id);
                            
    ?><div><a href="<?php echo $term_link?>"><?php echo $child->name ?></a><?php


                                $childs_of_child_ids 
    get_term_children($child->term_id"product_cat");
                                if(
    count($childs_of_child_ids) == 0)
                                {
                                  continue;
                                }
                                
    ?><ul class="sub-menu"><?php
                                  
    foreach($childs_of_child_ids as $child_of_child_id)
                                  {
                                    
    $child_of_child get_term($child_of_child_id"product_cat");
                                    
    $term_link get_term_link($child_of_child->term_id);
                                    if(
    $child_of_child->parent == $child->term_id)
                                    {
                                      
    ?><li><a href="<?php echo $term_link?>"><?php echo $child_of_child->name ?></a></li><?php
                                    
    }
                                  }
                                
    ?></ul><?php

                            ?>
    </div><?php
                            ?>
    </li><?php
                          
    }

                          
    ?>
                            </ul>
                        <?php
                        
    }
                    }
                    
    ?>
                </div>
            </div>
    Что тут можно исправить?
     
  2. sslion

    sslion

    Сообщения:
    9
    Симпатии:
    1
    Баллы:
    3
    Не знаю насколько это правильное решение, но вроде работает. Но мне кажется это жуткий костыль.
    Я тупо запихал нужные подкатегории в массив и отсортировал по ключу...
    PHP:
            <div class="cat-row">
                <div class="container cf">
                    <div class="cat-row__buttons"><a href="#" id="dlya-detej" class="cat-row__button active"><?php $term get_term(7,"product_cat"); echo $term->name;?></a><a href="#" id="dlya-mam" class="cat-row__button"><?php $term get_term(113,"product_cat"); echo $term->name;?></a></div>
                    <?php
                    $taxonomy 
    "product_cat";
                    
    /** Get all taxonomy terms */
                    
    $terms get_terms($taxonomy, array(
                            
    "orderby"    => "name",
                            
    "order"    => "ASC"//"orderby"    => "count",
                            
    "hide_empty" => false
                        
    )
                    );
                    
    $hierarchy _get_term_hierarchy($taxonomy);
                    foreach(
    $terms as $term)
                    {
                        if(
    $term->parent)
                        {
                          continue;
                        }
                        if(
    $hierarchy[$term->term_id])
                        {
                          if(
    $term->slug == "dlya-detej")
                          {
                            
    ?>
                              <ul class="cat-row__list active">
                            <?php
                          
    }
                          if(
    $term->slug == "dlya-mam")
                          {
                            
    ?>
                              <ul class="cat-row__list mom__list">
                            <?php
                          
    }


                          foreach(
    $hierarchy[$term->term_id] as $child)
                          {

                            
    $child get_term($child"product_cat");

                            switch (
    $child->slug) {
                              case 
    'podguzniki':
                                
    ?><li class="menu-item-has-children podguznik"><i></i><?php
                                
    break;
                              case 
    'mnogorazovaya-produktsiya-gloryes':
                                
    ?><li class="menu-item-has-children gloryes"><i></i><?php
                                
    break;
                              case 
    'detskoe-pitanie':
                                
    ?><li class="menu-item-has-children detskoe-pitanie"><i></i><?php
                                
    break;
                              case 
    'aksessuary-dlya-kormleniya':
                                
    ?><li class="menu-item-has-children aksesuari"><i></i><?php
                                
    break;
                              case 
    'gigiena-i-uhod':
                                
    ?><li class="menu-item-has-children gigiena"><i></i><?php
                                
    break;
                              case 
    'prorezyvateli-i-pustyshki':
                                
    ?><li class="menu-item-has-children pustishka"><i></i><?php
                                
    break;
                              case 
    'bytovaya-himiya':
                                
    ?><li class="menu-item-has-children ximia"><i></i><?php
                                
    break;
                              case 
    'detskaya-odezhda':
                                
    ?><li class="menu-item-has-children odejda"><i></i><?php
                                
    break;
                              case 
    'belyo-dlya-beremennyh-i-kormyashhih':
                                
    ?><li class="menu-item-has-children berem"><i></i><?php
                                
    break;
                              case 
    'aksessuary-dlya-kormleniya-dlya-mam':
                                
    ?><li class="menu-item-has-children aksesuar"><i></i><?php
                                
    break;
                              case 
    'produkty-dlya-laktatsii':
                                
    ?><li class="menu-item-has-children laktacia"><i></i><?php
                                
    break;
                              case 
    'sbory-v-roddom':
                                
    ?><li class="menu-item-has-children sbory"><i></i><?php
                                
    break;
                              case 
    'igrushki':
                                
    ?><li class="menu-item-has-children igrushki"><i></i><?php
                                
    break;
                              case 
    'kosmetika-aksessuary-dlya-kormleniya-dlya-mam':
                                
    ?><li class="menu-item-has-children kosmetika"><i></i><?php
                                
    break;
                              case 
    'slingi':
                                
    ?><li class="menu-item-has-children slingi"><i></i><?php
                                
    break;
                              default:
                                
    ?><li class="menu-item-has-children laktacia"><i></i><?php
                                
    break;
                            }

                            
    $term_link get_term_link($child->term_id);
                            
    ?><div><a href="<?php echo $term_link?>"><?php echo $child->name ?></a><?php


                                $childs_of_child_ids 
    get_term_children($child->term_id"product_cat");
                                if(
    count($childs_of_child_ids) == 0)
                                {
                                  continue;
                                }
                                
    ?><ul class="sub-menu"><?php
                                
                                $children 
    = [];
                                foreach(
    $childs_of_child_ids as $child_of_child_id)
                                  {
                                    
    $child_of_child get_term($child_of_child_id"product_cat");

                                    
    $term_link get_term_link($child_of_child->term_id);
                                    
    $child_name $child_of_child->name;
                                    if(
    $child_of_child->parent == $child->term_id)
                                    {
                                      
    $child_child = array("link" => $term_link"name" => $child_name);
                                      
    $children[$child_name] = $child_child;
                                    }
                                  }
                                  
    ksort($children);

                                foreach(
    $children as $child_child)
                                  {
                                      
    ?><li><a href="<?php echo $child_child["link"]; ?>"><?php echo $child_child["name"]; ?></a></li><?php
                                  
    }
                          
                                
    /*foreach($childs_of_child_ids as $child_of_child_id)
                                  {
                                    $child_of_child = get_term($child_of_child_id, "product_cat");
                                    

                                    $term_link = get_term_link($child_of_child->term_id);
                                    if($child_of_child->parent == $child->term_id)
                                    {
                                      ?><li><a href="<?php echo $term_link; ?>"><?php echo $child_of_child->name ?></a></li><?php
                                    }
                                  }*/
                                
    ?></ul><?php

                            ?>
    </div><?php
                            ?>
    </li><?php
                          
    }

                          
    ?>
                            </ul>
                        <?php
                        
    }
                    }
                    
    ?>
                </div>
            </div>
     
    • Нравится Нравится x 1