繁体   English   中英

如何在Wordpress中将分类ID添加到其子标签中?

[英]How to add taxonomy ID to its slug in wordpress?

我将自定义帖子类型及其分类注册为波纹管:

function book() {
    register_post_type('book', array(
        'labels' => array(
            'name' => __('Book'),
            'add_new_item' => "Add New",
            'edit_item' => __('Edit'),
            'new_item' => __('New'),
            'all_items' => __('All'),
            'view_item' => __('View'),
            'search_items' => __('Search'),
            'not_found' => __('Not found'),
            'not_found_in_trash' => __('Not anything found in the Trash'),
        ),
        'public' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        'show_in_nav_menus' => true,
        'publicy_queryable' => true,
        'exclude_from_search' => false,
        'menu_position' => 20,
        //'menu_icon' => plugins_url( 'images/image.png', __FILE__ ),
        //'menu_icon' => 'dashicons-book-alt3',
        'hierarchical' => TRUE,
        'query_var' => true,
        'supports' => array(
            'title', 'editor', 'thumbnail'
        ),
        'rewrite' => array('slug' => 'book', 'with_front' => false),
        'taxonomies' => array('post_tag'),
        'can_export' => true,
        'description' => __('Book')
            )
    );
}

function book_taxonomy() {
    register_taxonomy(
            'book_categories', //The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces). 
            'book', //post type name
            array(
                'hierarchical' => true,
                'label' => 'Book Cat', //Display name
                'query_var' => true,
                'show_in_nav_menus' => true,
                'rewrite' => array(
                    'slug' => 'book/c', // This controls the base slug that will display before each term
                    'with_front' => false // Don't display the category base before 
                )
            )
        );
    }
add_action('init', 'book');
add_action('init', 'book_taxonomy');

此代码有效。 分类法链接类似于: http:// localhost / ebook / book / c / book-1 /但我只想将分类ID添加到该链接中,例如: http:// localhost / ebook / book / c / 121 / book -1 /以“ 121”为分类链接。 反正有这样做吗? 非常感谢!

给您术语弹头:例如:term-slug-example

$slug = $term->slug; 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM