Support » Fixing WordPress » Custom post type category navigation

  • Hi!

    I’m going crazy on this one! I’ve searched google and forums for days looking for a solution to get this up an running…

    My scenario is as follows:
    I’ve created a custom post type with three custom taxonomies attached to it.

    1 of these are a hierarchical (category) and the other two are tags.
    I want the hierarchical one to act like the default post categories does in the menu.

    As so:
    Cat 1 (http://localhost/aoc/tavlingar/alla/)
    – Sub cat 1 (http://localhost/aoc/tavlingar/tavlingar-mtb/)
    – Sub cat 2 (http://localhost/aoc/tavlingar/tavlingar-lvg/)
    and so on.
    The permalinks works just as I want them, but the content just shows up in archive.php and doesn’t matter which sub-cat I’m in.

    I can’t get it to pick up the archive-aoc_tavlingar.php either, it just fall backs to archive.php

    This is what my functions.php looks like.

    add_action( 'init', 'create_aoc_tavlingar_cpt' );
    function create_aoc_tavlingar_cpt() {
    	register_post_type( 'aoc_tavlingar',
    			'labels' => array(
    				'name' => __( 'Tävlingar' ),
    				'singular_name' => __( 'Tävling' ),
    				'add_new' => __('Lägg till ny'),
    				'add_new_item' => __('Lägg till ny tävling'),
    				'edit' => __('Ändra'),
    				'edit_item' => __('Ändra tävling'),
    				'new_item' => __('Ny tävling'),
    				'view' => __('Visa tävling'),
    				'view_item' => __('Visa tävling'),
    				'search_items' => __('Sök tävling'),
    				'not_found' => __('Ingen tävling hittades'),
    				'not_found_in_trash' => __('Ingen tävling i papperskorgen')
    		'public' => true,
    		'menu_position' => 5,
    		'hierarchical' => false,
    		'query_var' => true,
    		'supports' => array('title','custom-fields','thumbnail'),
    		'rewrite' => array('slug' =>'tavling','with_front' => true),
    		'has_archive' => true,
    		'taxonomies' => true
    add_action( 'init', 'taxonomy_aoc_tavlingar');
    function taxonomy_aoc_tavlingar() {
    				'hierarchical' =>true,
    				'label' => 'Gren',
    				'query_var' => true,
    				'rewrite' => array('slug' =>'tavlingar','with_front' => true),
    add_action( 'init', 'taxonomy_aoc_tavlingar_tag_typ');
    function taxonomy_aoc_tavlingar_tag_typ() {
    				'hierarchical' =>false,
    				'label' => 'Typ av lopp',
    				'query_var' => true,
    				'rewrite' => array('slug' =>'tavlings_typ','with_front' => true),
    add_action( 'init', 'taxonomy_aoc_tavlingar_tag_misc', 0);
    function taxonomy_aoc_tavlingar_tag_misc() {
    				'hierarchical' =>false,
    				'label' => 'Övrigt',
    				'query_var' => true,
    				'rewrite' => array('slug' =>'tavlingar_ovrigt','with_front' => true),

    ANY help is appreciated!

Viewing 3 replies - 1 through 3 (of 3 total)
  • I believe archives only work for post types, not taxonomies. you would be looking to create a template with the following names to work for your taxonomies as declared above –

    • ‘aoc_taxonomy-tavlingar_gren.php’
    • ‘aoc_taxonomy-tavlingar_typ.php’
    • ‘aoc_taxonomy-tavlingar_misc.php’

    ‘archive-aoc_tavlingar.php’ would work to display posts in your Custom Post Type in an archive.

    Thanks for the answer!

    I see, soo the menu item of “cat 1” (in my custom post type) would be looking for a taxonomy-template and not a category-template like the default post posttype categories?

    However, I can’t get any of them to work. Not even the archive-aoc_tavlingar.php.

    This is my current permalink structure:

    Custom post type with rewrite – ….localhost/aoc/tavling (gives me 404)
    Taxonomy with categories – …localhost/aoc/tavlingar (gives me 404)
    Taxonomy with categories/cat 1 – localhost/aoc/tavlingar/alla (gives me archive.php)

    Single custom post type – localhost/aoc/tavling/”name of post” – (gives me a fully working single post template and working nav menu current classes and all seems fine!)


    Actually, when i renamed the aoc_tavlingar.php to tavlingar.php it actually finds it and displays it.

    “Taxonomy with categories – …localhost/aoc/tavlingar (gives me 404)”
    NOT true anymore..

    But since I can’t add this item in the menu without using custom links (which I guess will destroy the current_classes and whatnot)

    Therefor I have a category (alla) as the parent to all the other categories (mtb/cx/lvg etc)
    And I put that one i my top level menu and the others like sub-menus. And as I said, it all works nicely when I’m on a single CPT post.

    Lots of text and probably a lot of jibberish. Hope you get it!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom post type category navigation’ is closed to new replies.