Codex has_tag

WordPress 3.0 gave us custom taxonomies and since we’re using them regularly we’re also getting into conditional tags with our custom taxonomies.

Conditional tags for taxonomies differ from conditional tags for regular categories or tags. Below is an example of using a conditional tag for the standard ‘misc’ category found in WordPress.

[php]
if( is_category( ‘misc’ ) ) {
// do stuff with misc category
}
[/php]

When using conditional tags with custom taxonomies we need to use is_tax(). is_tax takes two parameters:

  1. $taxonomy – (optional) Name of your custom taxonomy
  2. $term – The term you want to be conditional

[php]
is_tax( $taxonomy, $term );
[/php]

So lets take the next step and use the conditional tag to detect the term ‘special’ in the taxonomy ‘ad_category’.

[php]
if( is_tax( ‘ad_category’, ‘special’ )) {
// do stuff if it is the special term in the taxonomy ad_category
}
[/php]

For more posts on how to build good WordPress themes check out the tag Building Quality WordPress Themes