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?
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 ofcategorycourses
, so wouldcategory-categorycourses.php
ifcategorycourses
was a normal category. If you click oncategorycourses
, 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 useget_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 likepage-tax.php
You need to change the loop in this template. Here is an example for the twentyfourteen theme.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 enterhttp://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 providedUPDATE1
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