ellp

WordPress list category, separated by letter, alphabetically

Jun 16th, 2015
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.03 KB | None | 0 0
  1. <?php
  2.                 $last_char = '';
  3.                 $args=array(
  4.                   'orderby' => 'title',
  5.                   'order' => 'ASC',
  6.                   'posts_per_page'=>-1,
  7.                   'caller_get_posts'=>1,
  8.                   'tag'=>"como-usar",
  9.                 );
  10.                 $my_query = new WP_Query($args);
  11.                 if( $my_query->have_posts() ) {
  12.                   /*echo 'Alphabetic index of all ' . count($my_query->posts) . ' posts';*/
  13.                   while ($my_query->have_posts()) : $my_query->the_post();
  14.                     $this_char = strtoupper(substr($post->post_title,0,1));
  15.                     if ($this_char != $last_char) {
  16.                       $last_char = $this_char;
  17.                       echo '<h2 class="a-z-titulo">'.$last_char.'</h2>';
  18.                     } ?>
  19.                     <div class="item">
  20.                         <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
  21.                             <?php echo get_the_post_thumbnail( $post_id, array( 100, 100) );?>
  22.                             <?php the_title(); ?>
  23.                         </a>
  24.                     </div>
  25.                     <?php
  26.                   endwhile;
  27.                 } //if ($my_query)
  28.                 wp_reset_query();  // Restore global post data stomped by the_post().
  29.                 ?>
Advertisement
Add Comment
Please, Sign In to add comment