WordPress.org

Ready to get started?Download WordPress

Forums

show category with sort alphabetical title (3 posts)

  1. genim
    Member
    Posted 4 years ago #

    hi...
    i want to have a page that says..

    A
    Archives
    Assists

    B
    Bike
    Booze
    Brand

    C.... etc...

    all those name are categories...i like to have a starting capital letter before the list.. and list all the categories with that starting letter..

    im not sure if theres a plugin that does that..
    basically i want to have a rolodex on my page..

  2. MichaelH
    Member
    Posted 4 years ago #

    I think you can modify the code here:
    http://wordpress.org/support/topic/288774

    need to change:

    $tags = get_terms( 'post_tag' );

    to

    $tags = get_terms( 'category' );
  3. Devin Walker
    Member
    Posted 3 years ago #

    Here's the code to display categories alphabetically in a list with clickable anchor links:

    <?php
    
    				$list = '';
    				$cats = get_terms('category');
    				$groups = array();
    				if( $cats && is_array( $cats ) ) {
    					foreach( $cats as $cat ) {
    						$first_letter = strtoupper( $cat->name[0] );
    						$groups[ $first_letter ][] = $cat;
    					}
    						if( !empty( $groups ) ) {{
    						$index_row .='<ul class="topindex">';
    					 foreach ($groups as $letter => $cats) {
    						$index_row .= '<li><h4><a href="#' . $letter . '" title="' . $letter . '">' . apply_filters( 'the_title', $letter ) . '</a></h4></li>';
    					}
    							$index_row .='</ul><br class="clear" />';} 
    
    							 $list .= '<ul class="index">';
    						 foreach( $groups as $letter => $cats ) {
    						$list .= '<li><a name="' . $letter . '"></a><h5><a href="#cats_top" title="back to top">' . apply_filters( 'the_title', $letter ) . '</a></h5>';
    							$list .= '<ul class="links">';
    							foreach( $cats as $cat ) {
    						   $url = attribute_escape( get_category_link( $cat->term_id ) );
    								$name = apply_filters( 'the_title', $cat->name );
    						   $list .= '<li><a title="' . $name . '" href="' . $url . '">' . $name . '</a></li>';
    
    				} 		 $list .= '</ul></li>';
    						} 	$list .= '</ul>';
    					}
    				}else $list .= '<p>Sorry, but no cats were found</p>';
    
    				?>
    			<a name="cats_top"></a>
    			<?php print $index_row; ?>
    			<?php print $list; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.