在WordPress中,可以通过自定义帖子类型和固定链接结合使用来实现在自定义帖子类型固定链接中添加自定义分类。下面是具体的步骤:
function create_book_post_type() {
$args = array(
'labels' => array(
'name' => 'Books',
'singular_name' => 'Book'
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'book'),
);
register_post_type('book', $args);
}
add_action('init', 'create_book_post_type');
function create_genre_taxonomy() {
$args = array(
'labels' => array(
'name' => 'Genres',
'singular_name' => 'Genre'
),
'public' => true,
'rewrite' => array('slug' => 'genre'),
);
register_taxonomy('genre', 'book', $args);
}
add_action('init', 'create_genre_taxonomy');
/%postname%/
,自定义帖子类型为"book",自定义分类为"genre",则帖子的链接可能类似于https://example.com/book/book-title/genre/genre-name/
。腾讯云相关产品和产品介绍链接地址:
领取专属 10元无门槛券
手把手带您无忧上云