Trying to create an A to Z index list of categories on a WP page. I’ve achieved this for the tags using this code:
<ul class="index-p clearfix">
<h3>A</h3>
<?php
$tags = get_tags( array('name__like' => "a", 'order' => 'ASC') );
foreach ( (array) $tags as $tag ) { ?>
<li>
<a href="<?php echo get_tag_link( $tag->term_id ) ?>">
<img src="<?php echo get_option('home'); ?>/wp-content/thumbs/<?php echo $tag->slug; ?>-small.jpg" alt="<?php echo $tag->name ?>" />
<span class="info">
<span class="name"><?php echo $tag->name ?></span>
<span class="number"><?php echo $tag->count ?> Clips</span>
</span>
</a>
</li>
<?php } ?>
</ul>
The above code will list all tags starting with the letter A. Is there a piece of code similar too the above to achieve the same thing for category’s.
Thanks
Have you tried
wp_list_categories();
? I’m not sure if you need finer control, but if you do, WP also hasget_categories();
The correct function is get_terms http://codex.wordpress.org/Function_Reference/get_terms