Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to figure out how to display a list of specific taxonomy (categorycourses).

In functions.php for the theme I have:

//Register custom taxonomy for courses-categories
$course_cat_args = array(
  'hierarchical' => true,
  'labels' => $course_cat_labels, //Other labels set before
  'show_ui' => true,
  'show_admin_column' => true,
  'query_var' => true,
  'rewrite' => array( 'hierarchical' => true )
);

register_taxonomy( 'categorycourses', array('course'), $course_cat_args );

The actual taxonomy is working fine in admin.

Now I'm trying to create a template for categorycourses at frontend that lists all coursecategories.

I've looked at the template hierarchy and I thought I should create a file with the taxonomy name categorycourses.php

So I created a file called categorycourses.php in the themes folder. I also tried creating categorycourses-categorycourse.php, archive-categorycourses.php but I just keep getting a 404 error.

Please bare with me. I understand lot of backend-stuff in WP, but I'm just learning how to create templates at frontend.

I'm able to create archive-pages for certain post typs, so rewrites rules and so on are working on my local server.

What am I doing wrong?

UPDATE 1. I've tried to create a file name taxonomy-categorycourses.php and with same result (404 error) I've flushed permalink-settings in admin by resaving them

I've also tried:

$course_cat_args = array(
  'hierarchical' => true,
  'labels' => $course_cat_labels,
  'show_ui' => true,
  'show_admin_column' => true,
  'query_var' => true,
  'rewrite' => array('slug' => 'soup')
);

register_taxonomy( 'categorycourses', array('course'), $course_cat_args );

I try to access the template with http://server/soup but still get the error. (after resaving permalink-settings in admin)

UPDATE2: *I think I've figured it out:* There don't seem to be any template for "root-taxonomy". You have to choose a specific coursecategory to act as a root.

In my case I've created this file:

taxonomy-categorycourses-semester2014.php

When I then access http://server/soup/semester2014 the expected template (taxonomy-categorycourses-semester2014.php) is shown.

But there seems no way to actually create a "root template for a taxonomy" like http://server/soup/ . Even if I create a template called taxonomy-categorycourses.php it does not work.

Is this correct?

share|improve this question
1  
So much for your SE handle.... –  Marc Dingena Apr 7 at 7:53
    
haha :-) But still. It didn't say I'm best at WP ;-) –  bestprogrammerintheworld Apr 7 at 8:55
    
Have a look also at this tutorial. –  Pieter Goosen Apr 7 at 10:41
    
Yes, but if you read_ "When taxonomy-brands.php is saved, we can now visit example.com/cameras/brands/canon to view our Custom Taxonomy archive:". It does not say that you can access example.com/cameras/brands directly. I've tried this as well, just by adding has_archive to true in the cpt, but still it does not work as I wanted to. –  bestprogrammerintheworld Apr 7 at 11:08

1 Answer 1

up vote 2 down vote accepted

What you want to do is impossible without a page.php type of template. There is no template hierarchy that support what you want to achieve. It works exactly the same with categories. taxonomy-categorycourses.php will not display a list of categorycourses, so would category-categorycourses.php if categorycourses was a normal category. If you click on categorycourses, you will be taken to a page that will display posts from that taxonomy or category.

If you need to show a list of terms or categories under a taxonomy, you will need to create a custom page.php template and use get_the_terms() to get a list of all the terms/categories attached to a taxonomy. wp_list_categories( $args ) will output the list, so you can modify this to display what you need. You can make a copy of your themes' page.php template and call it something like page-tax.php You need to change the loop in this template. Here is an example for the twentyfourteen theme.

 <?php
/**
 * Template Name: Page Tax
 */
get_header(); ?>

<div id="main-content" class="main-content">

    <div id="primary" class="content-area">
        <div id="content" class="site-content" role="main">

        <?php //list terms in a given taxonomy using wp_list_categories (also useful as a widget if using a PHP Code plugin)

            $taxonomy     = 'brands';
            $orderby      = 'name'; 
            $show_count   = 0;      // 1 for yes, 0 for no
            $pad_counts   = 0;      // 1 for yes, 0 for no
            $hierarchical = 1;      // 1 for yes, 0 for no
            $title        = '';

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

        ?>

        <ul>
            <?php wp_list_categories( $args ); ?>
        </ul>

        </div><!-- #content -->
    </div><!-- #primary -->
    <?php get_sidebar( 'content' ); ?>
</div><!-- #main-content -->

<?php
get_footer();

Just remember to change $taxonomy = 'brands'; to your taxonomy name. You can now create a new page in the "Add New Page" screen, set your page slug to the taxonomy name , and select this template. You can now enter http://server/categorycourses/ and you will be directed to this page you created.

Original Answer Your answer is right in the link you provided. The codex states it perfectly, you just need to implement it correctly. Your template should be called taxonomy-categorycourses.php. Please refer to the link you provided

UPDATE1 Hit me like a ton of bricks, had the same problem a while ago with a CPT, and I missed that when I looked at your code. For your custom template to work, you need to add 'has_archive' => true, to your arguments when registering your custom post type. For your info, go and check registering taxonomies and registering custom post types

share|improve this answer
    
Hm. I can't get this to work either (even it seems most logical). I still don't understand. Should I access the page with domain/taxonomy-categorycourses ? (I tried that and tried domain/categorycourses) but I still have the same issue. –  bestprogrammerintheworld Apr 7 at 8:52
    
Ok, thanks very much for the clarification and your effort trying to make sense of my question :-) –  bestprogrammerintheworld Apr 7 at 19:20
1  
It's my pleasure, just glad your problem is sorted –  Pieter Goosen Apr 7 at 19:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.