How to set custom category archive link to /%category%/%taxonomy%
P粉463824410
P粉463824410 2024-01-16 21:06:18
0
1
497

I am developing a WordPress site for the first time in a while and I would like to change the custom taxonomy archive link to /�tegory%/%taxonomy%.

In my use case, the category is TV series and the custom taxonomy represents the seasons. So if the post's category is "Star Trek: The Next Generation" and the custom category is "Season 1", I want /tng/s1 to be in taxonomy-season.php template. However, this URL currently displays the category.php template.

Can anyone help with the correct rewrite rules? Here's everything I know about custom taxonomies:

register_taxonomy(
    'season',
    'post',
    array(
        'public'  => true,
        'labels'  => array(
            'name' => 'season',
        ),
        'rewrite' => array(
            'slug' => '%category%',
        ),
    )
);

P粉463824410
P粉463824410

reply all(1)
P粉327903045

There is no native way in Wordpress to get categories by tags. The reason is that tags have nothing to do with categories, they are independent. That being said, the only way to get all the tags used by a specific category is to loop through every post in that category and get the tags for each post.

I recommend making subcategories for the parent TV show.

Then in category.php there is an if else statement (if it is a child post etc.)

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!