A
A
artemk7n2018-03-05 14:02:30
JavaScript
artemk7n, 2018-03-05 14:02:30

How to sort wordpress categories alphabetically?

Hello! Please help, I display categories like this

<?php 
      $i=1;
      $cat = get_query_var('cat');
      $categories = get_categories('parent='.$cat.''); 
      foreach ($categories as $category) { $i++; }
      if ($i > 1) {
        foreach ($categories as $category) { ?>
          <div class="smartphone wow fadeIn">
            <div class="smartphone-logo">
              <img src="<?php echo z_taxonomy_image_url($category->term_id); ?>"/>
            </div>
            <div class="smartphone-content">  
              <span><?php echo $category->name; ?></span>
            	<p></p>
              <a href="<?php echo get_category_link($category->term_id); ?>" class="blick"><span>Подробнее</span><img src="<?php bloginfo('template_directory'); ?>/img/icons/arrow-blue-icon.svg" width="7" height="11"></a>
            </div>
          </div>
        <?php } 
      } else {
      }
      ?>


How to make the categories appear alphabetically, and not by the time they were added - as it is now. Thank you very much in advance!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
DVamp1r3, 2018-03-05
@DVamp1r3

the function takes an array in which you can specify sorting and so on
https://wp-kama.ru/function/get_categories

S
Skeaper, 2019-01-06
@Skeaper

For example like this:

$args = array(
  'taxonomy' => 'category',
  'orderby' => 'name',
//	'parent' => $cat,
);
$categories = get_terms($args);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question