I switched my site from categories to taxonomies for my custom post but I am having trouble getting it to work the same way. For categories I could have templates named something like category-travel.php and then have my loop in that file. Now I am trying to replace the category list with something like this :

<?php  
$taxonomy = 'Gallery';
$orderby = 'name';
$show_count = 0;
$pad_counts = 0;
$hierarchical = 1;
$title="";

$args = array (
    'taxonomy' => $taxonomy,
    'orderby' => $orderby,
    'show_count' => $show_count,
    'pad_counts' => $pad_counts,
    'hierarchical' => $hierarchical,
    'title_li' => $title
    );

wp_list_categories($args) ?>

and in functions

register_taxonomy( 'Gallery', array( 'photo' ), array( 'hierarchical' => true, 'label' => 'Galleries', 'singular_label' => 'Gallery', 'rewrite' => true ) );

Now when I link from that generated list, something like mysite.com/gallery/name it is instead calling the archive.php rather than the taxonomy-gallery.php file I created. What am I doing wrong?

Sorry if this is a duplicate but I think that question is for something different and I cant believe that you would have to do a hack for this.

1 Answer
1

It looks like your issue is the name of your taxonomy has a capital letter, the first argument of register_taxonomy is to be all lowercase, no spaces as the documentation for the register_taxonomy function mentions here.

Change your code to the following and your taxonomy-gallery.php template will work correctly.

register_taxonomy( 'gallery', array( 'photo' ), array( 'hierarchical' => true, 'label' => 'Galleries', 'singular_label' => 'Gallery', 'rewrite' => true ) );

In the first bit of code you posted, you will also want to change the reference to the gallery taxonomy to be lowercase as well. Labels are fine with any case, but not actual names of taxonomies.

Leave a Reply

Your email address will not be published. Required fields are marked *