There are currently three primary ways to display custom post types in your themes:
- Taxonomy Cloud
- Custom Taxonomy Query
- Custom Taxonomy List
Taxonomy Cloud
Just as there are tag clouds, there are taxonomy clouds. To make it easy, both tags and clouds use the wp_tag_cloudfunction. In order to display an array of taxonomy categories in a cloud, we would use the following code:
<?php
wp_tag_cloud( array( 'taxonomy' => 'taxonomy_name_1','taxonomy_name_2' ) );
?>
Custom Taxonomy Query
Taxonomies can also be included in custom queries just like we did with post types above. For example, to display content from the taxonomy movie_genre, we would need to insert the following code into our template file:
$args = array(
'tax_query' => array(
'taxonomy' => 'movie_genre',
'field' => 'slug',
'terms' => 'comedy'
)
);
query_posts( $args );
First, we use the argument tax_query so that we can pass parameters that will allow us to query by slug or terms and return more accurate query results. In this example, we displayed posts tagged as “comedy” within the custom taxonomy “movie_genre”. Once again, like we did with post types, we can limit the number of posts that this query returns.
Custom Taxonomy Lists
To display a comma-delineated list of posts by taxonomy, we simply need to put the following somewhere in the loop:
<?php the_terms( $post->ID, '{taxonomy name}', '{Displayed Title}: ', ', ', ' ' ); ?>
This is a part of WordPress Post Types and Taxonomies tutorial.
The post WordPress Post Types and Taxonomies – Displaying Taxonomies appeared first on Tutorial Mini.
Related posts:
- WordPress Post Types and Taxonomies – Displaying Post Types
- WordPress Post Types and Taxonomies – Integrating Taxonomies
- WordPress Post Types and Taxonomies – Integrating Post Types
via Tutorial Mini http://tutorialmini.com/wordpress-post-types-and-taxonomies-displaying-taxonomies/
No comments:
Post a Comment