I’m trying to output the title of a taxonomy page when viewing it.
So like, if I was on a ‘tag’ page I would go:
<?php if (is_tag()) {?>
<h1><?php single_cat_title(); ?></h1>
<?php } ?>
But how would I achieve the same thing for if the user is viewing a specific taxonomy page?
is_taxonomy()
doesn’t exist.
Found this answer for anyone else wondering.
Follow this guide: http://justintadlock.com/archives/2009/06/04/using-custom-taxonomies-to-create-a-movie-database
Right down the bottom, the line wanted was:
can be done superdupereasy with:
name
, when beeing on some custom taxonomy page, will be the taxonomy term., e.g. on something likeexample.com/books/Fiction
, this will echofiction
.Instead of
name
you could also usetaxonomy
, which will echobooks
.And shortly spoken, taxonomies are NOT categories or pages or comments, they are something you declare, like “products” or “books”. Using that you unlock WordPress’es Custom Post Type functionality. You can make your own
archive-products.php
,page-products.php
,single-products.php
and have big fun with it. 🙂Here is a complete example, which modifies the title only for taxonomy listing pages, using the function
is_tax()
You can use the single_term_title() function.
I think it is easy enough to use the single_cat_title() function.
See here for more details.