D
D
dimasan572021-11-26 12:30:14
WordPress
dimasan57, 2021-11-26 12:30:14

How to display wordpress category posts alphabetically with letter?

In general, the essence of the issue is in the picture. I found a solution how to sort alphabetically, but I don’t know how to display a letter.61a0a917c5dab733807038.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WP Panda, 2021-11-26
@wppanda5

something like this

$_flag = []; // онтрольный массив
  if ( have_posts() ) : while ( have_posts() ) : the_post();
  
    $first = mb_substr( get_the_title(), 0, 1 );

    if ( ! in_array( $first, $_flag ) ) { //проверка на наличие первой буквы в массиве
        // если ее там нет, выводим букву и добавляем в контрольный мавссив
      printf( '<h3>%s</h3>', $first );
      $_flag[] = $first;
    }

    /**
         * тут выод записи
         */
    
  endwhile;
  else :
  endif;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question