Custom taxonomy list page?

There is nothing built-in to WordPress to provide an “index” page for your taxonomy as your question implies there should be (and I agree, there should be! But there isn’t.)

Instead you have to hack it and one way to do that is to create a page called “Main Ingredient” with a main-ingredient URL slug and assign it a page template for your theme that you will create (maybe) called “Main Ingredient List”:

Screenshot showing where to set Page Template in WordPress
(source: mikeschinkel.com)

Here’s a starting point; maybe use the file name page-main-ingredient-list.php for your page template:

<?php
/*
Template Name: Main Ingredient List
*/
get_header();
$main_ingredients = get_terms('main-ingredient');
foreach($main_ingredients as $main_ingredient) {
  $dishes = new WP_Query(array(
    'post_type' => 'dish',
    'post_per_page'=>-1,
    'taxonomy'=>'main-ingredient',
    'term' => $main_ingredient->slug,
  ));
  $link = get_term_link(intval($main_ingredient->term_id),'main-ingredient');
  echo "<h2><a href=\"{$link}\">{$main_ingredient->name}</a></h2>";
  echo '<ul>';
  while ( $dishes->have_posts() ) {
    $dishes->the_post();
    $link = get_permalink($post->ID);
    $title = get_the_title();
    echo "<li><a href=\"{$link}\">{$title}</a></li>";
  }
  echo '</ul>';
}
get_footer();

And then here’s what the page looks like with some dummy data on my test site:

Screenshot of a Taxonomy Index page for a WordPress Site

Leave a Comment

tech