wordpress 自定义_如何将WordPress类别转换为自定义分类法

wordpress 自定义

Do you want to convert your WordPress categories into custom taxonomies? Categories are one of the two default taxonomies that help you sort your content. However, WordPress also allows you to create and use custom taxonomies. In this article, we will show you how to easily convert WordPress categories into custom taxonomies.

您想将WordPress类别转换为自定义分类法吗? 类别是可帮助您对内容进行排序的两个默认分类法之一。 但是,WordPress还允许您创建和使用自定义分类法。 在本文中,我们将向您展示如何轻松地将WordPress类别转换为自定义分类法。

How to Convert WordPress Categories to Custom Taxonomies
为什么以及何时需要将类别转换为自定义分类法 (Why and When Do You Need to Convert Categories to Custom Taxonomies)

Categories and tags are the two default taxonomies in WordPress. Taxonomies are used to sort and organize content into different topics.

类别和标签是WordPress中的两个默认分类法。 分类法用于将内容分类和组织为不同的主题。

Apart from the default taxonomies, WordPress also allows you to create custom taxonomies which you can use with existing post types or with custom post types. For more on this topic, see our article on when do you need a custom post type or taxonomy in WordPress.

除了默认分类法之外,WordPress还允许您创建自定义分类法 ,可将其与现有帖子类型自定义帖子类型一起使用 。 有关此主题的更多信息,请参阅我们的文章,有关何时需要 WordPress中的自定义帖子类型或分类法

As your website grow, you might find a need to convert your categories into a custom taxonomy. For example, let’s say that you have a category called topics with a lot of sub-categories. It would be time-consuming to edit each post and file it under your new custom taxonomy.

随着网站的发展,您可能需要将类别转换为自定义分类法。 例如,假设您有一个名为主题的类别,其中包含许多子类别。 编辑每个帖子并将其归档为新的自定义分类法将非常耗时。

Wouldn’t it be nice if you could bulk convert some or all of your categories to the new custom taxonomy?

如果您可以将部分或全部类别批量转换为新的自定义分类法,那不是很好吗?

Let’s take a look at how you can easily convert categories to custom taxonomies without manually editing each post.

让我们看一下如何轻松地将类别转换为自定义分类法,而无需手动编辑每个帖子。

将WordPress类别转换为自定义分类法 (Converting WordPress Categories to Custom Taxonomies)

First thing you need to do is install and activate Taxonomy Switcher plugin. For more details, see our step by step guide on how to install a WordPress plugin.

您需要做的第一件事是安装并激活Taxonomy Switcher插件。 有关更多详细信息,请参阅有关如何安装WordPress插件的分步指南。

Upon activation, you need to visit Tools » Taxonomy Switcher page in your WordPress admin area to convert categories to custom taxonomies.

激活后,您需要访问WordPress管理区域中的“ 工具”»“分类法切换器”页面,以将类别转换为自定义分类法。

Taxonomy Switcher

On this page, you can select the taxonomies you want to convert. For this tutorial, we will select ‘Categories’ as the taxonomy we want to switch from, and ‘Topics’ as the custom taxonomy we want to switch to.

在此页面上,您可以选择要转换的分类法。 在本教程中,我们将选择“类别”作为我们要转换的分类法,并选择“主题”作为我们要转换的自定义分类法。

Select taxonomies

If you want to convert all categories to a custom taxonomy, then you can go ahead and click on the ‘Switch Taxonomies’ button.

如果要将所有类别转换为自定义分类法,则可以继续并单击“切换分类法”按钮。

The plugin will convert all categories to your selected custom taxonomy. You will see a success message like this:

该插件会将所有类别转换为您选择的自定义分类法。 您将看到类似以下的成功消息:

Successfully switched taxonomies

If you just want to convert specific categories, then you will need to add the IDs of those categories next to ‘Comma separated list of term ids to switch’ field. See our article on how to find category IDs in WordPress for more details.

如果您只想转换特定的类别,则需要在“逗号分隔的要切换的术语ID列表”字段旁边添加这些类别的ID。 有关更多详细信息,请参见有关如何在WordPress中查找类别ID的文章。

Skip categories

Additionally, if you want to skip child categories of a specific category, then you can add the IDs of the parent category next to ‘Limit taxonomy switch for child terms of a specific parent’ option.

此外,如果要跳过特定类别的子类别,则可以在“限制特定父类别的子类别的分类开关”选项旁边添加父类别的ID。

Don’t forget to click on the ‘Switch Taxonomy’ button to save your changes.

不要忘记单击“切换分类法”按钮以保存您的更改。

设置从类别到自定义分类的重定向 (Setting Up Redirects from Category to Custom Taxonomy)

After you switch categories to a custom taxonomy, the category archive page will now show a 404 error page. This is nothing to be worried about if your website is not live yet.

在将类别切换到自定义分类法之后,类别存档页面现在将显示404错误页面 。 如果您的网站尚未启用,则无需担心。

However if your website is live, then search engines may have already crawled your category pages and indexed them. This means that those pages can appear in search results and users coming from search engines will see a 404 error page.

但是,如果您的网站是在线的,则搜索引擎可能已经对您的类别页面进行了爬网并将它们编入索引。 这意味着这些页面可以出现在搜索结果中,并且来自搜索引擎的用户将看到404错误页面。

To fix this, you need to redirect users to the new taxonomy page for each category.

要解决此问题,您需要将用户重定向到每个类别的新分类页面。

Luckily, there is an easy fix for that.

幸运的是,有一个简单的解决方法。

First, you will need to install and activate the Redirection plugin. For more details, see our step by step guide on how to install a WordPress plugin.

首先,您需要安装并激活重定向插件。 有关更多详细信息,请参阅有关如何安装WordPress插件的分步指南。

Upon activation, you need to visit Tools » Redirection page. In the Source URL field, you need to enter /category/.* and in the Target URL field you need to enter your custom taxonomy slug, e.g. /topic/$1

激活后,您需要访问工具»重定向页面。 在“源URL”字段中,您需要输入/category/.* ,在“目标URL”字段中,您需要输入自定义分类标准段,例如/ topic / $ 1

Set up redirects

Next, you need check the box next to ‘Regex’ option, and then click on ‘Add Redirect’ button.

接下来,您需要选中“ Regex”选项旁边的框,然后单击“添加重定向”按钮。

This redirect will now send all category archive traffic to your custom taxonomy. Only use this, if you don’t want to use categories at all.

现在,此重定向会将所有类别存档流量发送到您的自定义分类法。 如果您根本不想使用类别,请仅使用此选项。

If you want to redirect individual categories to a custom taxonomy page, then see our beginner’s guide on setting up redirects in WordPress with detailed step by step instructions.

如果您要将各个类别重定向到自定义分类页面,请参阅有关在WordPress中设置重定向的初学者指南,其中包含详细的分步说明。

We hope this article helped you learn how to convert WordPress categories to custom taxonomies. You may also want to see our guide on how to style individual categories differently in WordPress to style your custom taxonomy templates.

我们希望本文能帮助您学习如何将WordPress类别转换为自定义分类法。 您可能还希望查看我们的指南, 了解如何在WordPress中不同的方式设置各个类别的样式以设置自定义分类模板的样式。

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

如果您喜欢这篇文章,请订阅我们的YouTube频道 WordPress视频教程。 您也可以在TwitterFacebook上找到我们。

翻译自: https://www.wpbeginner.com/wp-tutorials/how-to-convert-wordpress-categories-to-custom-taxonomies/

wordpress 自定义

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值