J
J
jenya77712017-04-25 13:16:31
WordPress
jenya7771, 2017-04-25 13:16:31

How to make CNC with categories for taxonomy?

Hello, I saw a lot of similar questions asked, but there are no sensible answers with a solution.
It is necessary to make CNC so that they have categories, subcategories and the name of the product itself, like breadcrumbs, and how to set up a template for them to display posts and categories?

function create_post_type() {
    register_post_type( 'service',
        array(
            'labels' => array(
                'name' => __( 'Услуги' ),
                'singular_name' => __( 'Услуга' ),
                'add_new' =>  __( 'Новая услуга' ),
                'edit_item' =>  __( 'Редактировать услугу' )
            ),
            'public' => true,
            'has_archive' => true,
            'supports' => array('title','editor','thumbnail'),
            'rewrite' => array( 'slug' => 'service', 'hierarchical' => true ),
        )
    );
}

add_action( 'init', 'create_custom_taxonomy');

function create_custom_taxonomy() {
    // Add new taxonomy, make it hierarchical (like categories)
    $args = array(
        'labels' => array(
            'name' => __( 'Рубрики услуг' ),
        ),
        'hierarchical'      => true,
        'show_ui'           => true,
        'show_admin_column' => true,
        'query_var'         => true,
        'rewrite'           => array( 'slug' => 'services', 'hierarchical' => true ),
    );

    register_taxonomy( 'services', array( 'service' ), $args );
}

After adding this code for the product page
'rewrite' => array( 'slug' => 'service', 'hierarchical' => true ),

Nothing has changed, only the slug changes when it changes and again it does not find a template with a different slug, and categories and subcategories do not appear in the address, how can I fix this? Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
realkludge, 2017-05-17
@jenya7771

In the admin panel, on the /wp-admin/options-permalink.php
page, select arbitrarily and write there:
All categories and subcategories to which the page belongs will be displayed in the URL.
Full list of available tags here:
https://codex.wordpress.org/Using_Permalinks

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question