WordPress gives us categories, and we can create custom taxonomies, but this week I discovered that there is nowhere on your average WordPress site where you can actually list your categories, unless it’s an archive page or a 404 page. It isn’t something I’ve ever needed yet, and according to my searching, that’s true for most everyone (a lot of fruitless searching), but hopefully there is at least one person out there who wants to know how to do this, because I figured it out–here’s how to make a custom page template to list your categories or other taxonomies.
I’m building a website with a custom post type with several taxonomies. I needed to create couple pages which would show each taxonomy as a list. The Codex showed me how I could PHP my way into it, but it necessitated hard coding in the taxonomy name, which doesn’t help me, as I would really like to have this available for multiple taxonomies.
Genesis comes with a blog page template built in, and you can use it to create blog type pages for categories (and post types and pages) by adding a custom field with a name of
query_args and a value of
cat=3, where 3 is the ID of your category. You can modify the field further with all kinds of arguments, like:
You May Also Like:
So your blog template will show your portfolio custom post type, sorted alphabetically.
My thought was to use something similar for the category lists, but it took some digging. In the Codex, I found the page on get_terms (see the custom taxonomy example), which pointed me in the right direction–I just needed to set it up to be configurable from the front end.
The key was to set up my template and custom fields to separate the taxonomy from the arguments. Entering a taxonomy custom field is required; the arguments are not, unless you want your taxonomy list to be in a certain order. Here’s the template:
Name the template page_taxonomy.php (or whatever you want to call it), upload it to your theme file, and voila! You’ll have a new template to choose from when you create a page.
Create your page, name it whatever you want, call it whatever you want (you can set the permalink to be /category, actually, as that throws a 404, so I used my taxonomy), add in content (it will show above your list of terms), set the page template, and then add your custom fields. You must enter a field named
taxonomy and the value will be your taxonomy–for example,
category. Entering arguments for order or anything is optional.
You could trick this out more, either in the template or CSS–the template at this point is just a simple list, with each li set at 50% and floated left, but the hard work of setting it up is done.
If you find this useful, I’d love to see what you do with it!