Creating a page template that lists all of your WordPress taxonomies
A taxonomy is an organization or classification of things by relationship. The taxonomy system in WordPress is largely untapped but has a lot of potential.
By default, WordPress comes loaded with three taxonomies:
link_category. But, plugins and themes can extend this to create even more.
What I’ll be showing you in this tutorial is how to make a page template that displays each taxonomy on your site in a cloud format. You can only do this with WordPress 2.8+. Prior to 2.8, this was only possible with post tags.
Creating the page template
First, you should copy your theme’s
page.php file. Save it as
taxonomy-clouds.php. Near the top of it, you’ll see this line of code:
<?php get_header(); ?>
You’ll want to change that to:
<?php /** * Template Name: Taxonomy Clouds */ get_header(); ?>
If you need more information on this process, check out my tutorial on how to create page templates.
Adding the taxonomy clouds to your template
Farther down the file, you should see something that looks like this in the code:
<?php the_content(); ?>
Just below that, we’ll add our new code. What we’re actually doing is loading all of the available taxonomies and looping through them. During each loop, the wp_tag_cloud() template tag will display the cloud.
<?php global $wp_taxonomies; ?> <?php if ( is_array( $wp_taxonomies ) ) : ?> <?php foreach ( $wp_taxonomies as $tax ) : ?> <h2 class="taxonomy-label"><?php echo $tax->label; ?></h2> <p class="taxonomy-cloud"> <?php wp_tag_cloud( array( 'taxonomy' => $tax->name, 'number' => 0 ) ); ?> </p><!-- .taxonomy-cloud --> <?php endforeach; ?> <?php endif; ?>
Mixing two untapped features of WordPress
I’ve previously called page templates the untapped potential of WordPress, and the same definitely goes for taxonomies. What I hope to continue doing with this series is broadening our view of what WordPress can do and get people kick-started in thinking of unique ways of extending the platform.
Have a little fun with your new page template. Try out some different parameters with the
wp_tag_cloud() function. See what you can come up with.
This tutorial is for WordPress version 2.8+.