Displaying taxonomy as category page?
-
I’d like to display every post tagged with a certain taxonomy on a page. Here’s what I’ve got so far…
In functions.php, I’ve created a custom post type and custom taxonomy:
// IMAGE GALLERY register_post_type( 'gallery', array( 'labels' => array( 'name' => 'Image Gallery', 'singular_name' => 'Gallery Image', 'add_new' => 'Add new gallery image', 'add_new_item' => 'Add gallery image', 'new_item' => 'New gallery image', 'view_item' => 'View gallery images', 'edit_item' => 'Edit gallery image', 'not_found' => __('No gallery images found'), 'not_found_in_trash' => __('No gallery images found in Trash') ), 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'query_var' => true, 'rewrite' => true, 'capability_type' => 'post', 'exclude_from_search' => true, 'hierarchical' => false, 'menu_position' => null, 'supports' => array('title', 'thumbnail'), 'taxonomies' => array('image_category') ) );
// Custom Taxonomies function asw_register_taxonomies() { register_taxonomy("image_category", array("gallery"), array( "hierarchical" => true, "label" => __('Image Categories', 'gallery'), "singular_label" => "Image Category", "query_var" => true, "rewrite" => true)); }
The taxonomies show up perfectly in the post type and are successfully saved with the post.
Then I have a template for the gallery which contains this code for the taxonomy list:
<?php // LIST IMAGE CATEGORIES $categories = array( 'show_option_all' => '', 'orderby' => 'name', 'order' => 'ASC', 'style' => 'list', 'show_count' => 0, 'hide_empty' => 1, 'use_desc_for_title' => 1, 'child_of' => 0, 'feed' => '', 'feed_type' => '', 'feed_image' => '', 'exclude' => '', 'exclude_tree' => '', 'include' => '', 'hierarchical' => true, 'title_li' => __( '' ), 'show_option_none' => __('No categories'), 'number' => null, 'echo' => 1, 'depth' => 0, 'current_category' => 0, 'pad_counts' => 0, 'taxonomy' => 'image_category', 'walker' => null ); ?> <?php wp_list_categories( $categories ); ?>
…which works like a charm, displaying all the categories of the taxonomy. But when I click on one of the links in the list, it sends me to [url]/image_category/sample-images/ — which uses index.php and contains a “page not found” error.
I have a template named taxonomy-image_category.php which contains a standard loop, but WP isn’t using it; it loads the category from index.php instead. I even tried creating a generic taxonomy.php page, but no cigar. Does anyone know what I’m missing?
- The topic ‘Displaying taxonomy as category page?’ is closed to new replies.