对多个分类法使用相同的永久链接结构

问题描述 投票:0回答:2

我有一个 WP 网站,其中有 3 个分类法,主要类别、公司和地区。我正在寻找它们都使用相同的永久链接结构,例如:

site.com/{category-slug} site.com/{company-slug} site.com/{region-slug}

有没有办法让这个工作并重写functions.php中的url?我已经尝试了几种方法,但有时它们可以工作,但然后主页404。

提前致谢

php wordpress wordpress-theming permalinks timber
2个回答
0
投票

你尝试过这个吗?

    function change_custom_taxonomy() {
    $custom_category_args = get_taxonomy( 'custom_category_slug' );
    $custom_category_args->show_admin_column = true;
    $custom_category_args->rewrite['slug'] = 'category_slug_which_you_want';
    $custom_category_args->rewrite['with_front'] = false;
    register_taxonomy( 'custom_category_slug', 'category_slug_which_you_want', (array) $custom_category_args );
}
add_action( 'init', 'change_custom_taxonomy', 11 );

0
投票

要实现这一点,您确实可以使用functions.php文件来重写URL。

首先添加自定义重写规则并使用 'flush_rewrite_rules()' 函数刷新重写规则。此外,请确保您的自定义重写规则不与现有规则冲突。

请记住,对永久链接问题进行故障排除有时可能会导致暂时的 404 错误,但找到解决方案的决心至关重要。

您积极主动的态度和探索不同方法的意愿表明您致力于提供无缝的用户体验。继续试验,并毫不犹豫地从 WordPress 论坛或开发者社区寻求见解 - 您的坚持很可能会成功实现您想要的永久链接结构。

© www.soinside.com 2019 - 2024. All rights reserved.