Overall, taxonomies are pretty easy to implement in your functions.php file. Remember, you can go hierarchical with them or treat them like tags, so the more complex you want the greater the difficulty. Either way, here is a quick rundown of how to incorporate these into your theme.
Again, open up your functions.phpfile and insert the following code:
function movie_taxonomy() {
register_taxonomy(
'movie_review',
'mysite_reviews',
array(
'hierarchical' => true,
'label' => 'Movie Review',
'query_var' => true,
'rewrite' => array('slug' => 'movie-reviews')
)
);
}
add_action( 'init', 'movie_taxonomy' );
To break this down, first we give the taxonomy a formal name (“movie_review”), and we place it under the post type “mysite_reviews”, which we created earlier.
function movie_taxonomy() {
register_taxonomy(
'movie_review',
'mysite_reviews',
Then we pass these values:
array(
'hierarchical' => true,
'label' => 'Movie Review',
'query_var' => true,
'rewrite' => array('slug' => 'movie-reviews')
)
This supplies the following arguments:
- hierarchical – When set to “true”, the taxonomy will act more like a category. There can be parent taxonomies and nested taxonomies allowing for greater depth of classification. When set to “false”, they act like just like tags.
- label – As with the post types above, this is the label that the taxonomy will publicly recieve.
- query_var – When set to “true” this taxonomy becomes a queryable element.
- rewrite – This sets the URL rewrite. Now posts in this taxonomy will be displayed as http://mysite.com/movie-reviews/{post title}/.
The end result within our admin nav should look like this:
Furthermore, we can dive into that interface and add more classification categories and structure. That interface looks similar to the category interface that you may already be familiar with.
From this interface, you can edit the slugs of the various categories within your taxonomy, create new categories, and determine parent and child categories.
This is a part of WordPress Post Types and Taxonomies tutorial.
The post WordPress Post Types and Taxonomies – Integrating Taxonomies appeared first on Tutorial Mini.
Related posts:
- WordPress Post Types and Taxonomies – Integrating Post Types
- WordPress Post Types and Taxonomies – Displaying Post Types
- WordPress Post Types and Taxonomies
via Tutorial Mini http://tutorialmini.com/wordpress-post-types-and-taxonomies-integrating-taxonomies/
No comments:
Post a Comment