Alphabetized Glossary

Sort post content alphabetically, and divide each letter section with the appropriate letter.

<?php query_posts('post_type=glossary&orderby=title&order=ASC&posts_per_page=-1');
$current_letter = '';
if ( have_posts() ) while ( have_posts() ) : the_post(); 

	$title_letter = get_the_title();
	$letter = strtolower( substr( $title_letter, 0, 1 ) ); ?>

	<div class="glossary">
		<div class="width">
		    
		    <?php if ( $letter != $current_letter ) {
		        $current_letter = $letter; ?>
		        
		        
		        <div class="key">
					<a class="header-offset" id="letter-<?php echo $key; ?>"></a>
					<?php echo $letter; ?>
					<div class="divider"></div>
				</div>
		        
		    <?php } ?>
	    
		    <div class="term">
				<div class="term-name"><?php the_title(); ?></div>
				<div class="term-content"><?php the_content(); ?></div>
			</div>
	    </div>
    </div>
<?php endwhile; // end of the loop. ?>

Source.https://wordpress.stackexchange.com/questions/10561/sort-posts-alphabetically-by-custom-field-value-insert-divider-between-differen

Leave a Reply

Posted in php
katherine as a flat graphic icon

About Me

I’m an African / Ojibwe First Nations Web Developer living in Winnipeg, Manitoba.

Visit the Tips and Blog to see what I’m working on.