• 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 (https://localhost/aoc/tavlingar/alla/)
    – Sub cat 1 (https://localhost/aoc/tavlingar/tavlingar-mtb/)
    – Sub cat 2 (https://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',
    		array(
    			'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() {
    	register_taxonomy(
    		'aoc_tavlingar_gren',
    		'aoc_tavlingar',
    			array(
    				'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() {
    	register_taxonomy(
    		'aoc_tavlingar_typ',
    		'aoc_tavlingar',
    			array(
    				'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() {
    	register_taxonomy(
    		'aoc_tavlingar_misc',
    		'aoc_tavlingar',
    			array(
    				'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.

    Thread Starter osby

    (@osby)

    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!)

    Thread Starter osby

    (@osby)

    Hupp!

    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.