Display categories that start with a certain letter
-
Hey guys,
I’m trying to display categories that are grouped by the letter they start with. EgA
Apples,
Apricots
Anjas
B
Bananas
Beats
C
etc etcI really don’t want to create sub-categories under each letter. Instead, I’d prefer to do this programmatically if possible. My problem is that I’m a complete nubie to php!
The code below by gcarson shows how to do it perfectly for tags. However, I can’t (for the life of me) figure out how to do the same thing with categories. Can anyone help? Any advice would be much appreciated.
<?php $tags = get_tags( array('name__like' => "a", 'order' => 'ASC') ); $tags_count = count($tags); $count = intval( $tags->count ); $percolumn = ceil($tags_count / 3); for ($i = 0;$i < $tags_count;$i++): if ($i < $percolumn): $tag_left .= ' <li><a href="'. get_tag_link($tags[$i]->term_id) . '"rel="tag">' . $tags[$i]->name .' (' . $tags[$i]->count . ')</a></li> ' . "\n"; elseif ($i >= $percolumn && $i < $percolumn*2): $tag_mid .= ' <li><a href="'. get_tag_link($tags[$i]->term_id) . '"rel="tag">' . $tags[$i]->name .' (' . $tags[$i]->count . ')</a></li> ' . "\n"; elseif ($i >= $percolumn*2): $tag_right .= ' <li><a href="'. get_tag_link($tags[$i]->term_id) . '"rel="tag">' . $tags[$i]->name .' (' . $tags[$i]->count . ')</a></li> ' . "\n"; endif; endfor; ?> <div class="list"> <ul> <?php echo $tag_left; ?> </ul> </div> <div class="listlist"> <ul> <?php echo $tag_mid; ?> </ul> </div> <div class="list"> <ul> <?php echo $tag_right; ?> </ul> </div>
For reference, this is the post the code came from: http://wordpress.org/support/topic/a-z-index-list-of-tags
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Display categories that start with a certain letter’ is closed to new replies.