Hallo,
ich suche und probiere nun schon eine Weile rum und bin eigentlich sehr verwundert, dass ich noch nicht die richtige Lösung gefunden habe.
Ich habe mir einen zusätzlichen Post-Type namens Artikel erstellt. Darin sollen diverse Geräte rein, welche dann über die Taxonomies in verschiedene Kategorien unterteilt werden.
Als Beispiel:
Der Artikel Beamer XYZ
ist der Kategorie Beamer & Co. sowie der Unterkategorie Beamer zugeordnet.
Der Permalink müsste ja nun lauten:
Tut er aber nicht, er lautet einfach nur:
Ich sehe vielleicht den Wald vor lauter Bäumen nicht mehr und muss deswegen hier nach Hilfe Fragen, wie ich denn auch die letzte Unterkategorie in den Permalink bekomme.
Vielleicht hat ja auch jemand eine ganz einfach Lösung mittels Plugin parat.
Hier mal der Auszug aus der functions.php:
function artikel_taxonomy() {
register_taxonomy(
'artikel_categories', //The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces).
'artikel', //post type name
array(
'hierarchical' => true,
'label' => 'Artikel-Kategorien', //Display name
'query_var' => true,
'rewrite' => array(
'slug' => 'vermietung', // This controls the base slug that will display before each term
'with_front' => false // Don't display the category base before
)
)
);
}
add_action( 'init', 'artikel_taxonomy');
function filter_post_type_link( $link, $post) {
if ( $post->post_type != 'artikel' )
return $link;
if ( $cats = get_the_terms( $post->ID, 'artikel_categories' ) )
$link = str_replace( '%artikel_categories%', array_pop($cats)->slug, $link );
return $link;
}
add_filter('post_type_link', 'filter_post_type_link', 10, 2);
//Registering Custom Post Type Themes
add_action( 'init', 'register_artikelpost', 20 );
function register_artikelpost() {
$labels = array(
'name' => _x( 'Artikel', 'catchthemes_custom_post','catchthemes' ),
'singular_name' => _x( 'Artikel', 'catchthemes_custom_post', 'catchthemes' ),
'add_new' => _x( 'erstellen', 'catchthemes_custom_post', 'catchthemes' ),
'add_new_item' => _x( 'Artikel erstellen', 'catchthemes_custom_post', 'catchthemes' ),
'edit_item' => _x( 'Artikel bearbeiten', 'catchthemes_custom_post', 'catchthemes' ),
'new_item' => _x( 'neuer Artikel', 'catchthemes_custom_post', 'catchthemes' ),
'view_item' => _x( 'Artikel ansehen', 'catchthemes_custom_post', 'catchthemes' ),
'search_items' => _x( 'Artikel suchen', 'catchthemes_custom_post', 'catchthemes' ),
'not_found' => _x( 'kein Artikel gefunden', 'catchthemes_custom_post', 'catchthemes' ),
'not_found_in_trash' => _x( 'kein Artikel im Papierkorb gefunden', 'catchthemes_custom_post', 'catchthemes' ),
'parent_item_colon' => _x( 'Eltern-Artikel:', 'catchthemes_custom_post', 'catchthemes' ),
'menu_name' => _x( 'Artikel', 'catchthemes_custom_post', 'catchthemes' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => false,
'description' => 'Artikel zur Vermietung',
'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'post-formats', 'custom-fields' ),
'taxonomies' => array( 'post_tag','artikel_categories'),
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'show_in_nav_menus' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'query_var' => true,
'can_export' => true,
'rewrite' => array('slug' => 'vermietung/%artikel_categories%','with_front' => false),
'public' => true,
'has_archive' => 'vermietung',
'capability_type' => 'post'
);
register_post_type( 'artikel', $args ); //max 20 charachter cannot contain capital letters and spaces
}
add_filter('pre_get_posts', 'query_post_type');
function query_post_type($query) {
if(is_category() || is_tag()) {
$post_type = get_query_var('post_type');
if($post_type)
$post_type = $post_type;
else
$post_type = array('post','artikel');
$query->set('post_type',$post_type);
return $query;
}
}
Alles anzeigen