url wordpress_如何在WordPress URL中包括类别和子类别

url wordpress

Recently one of our readers asked us how to include category and subcategory in WordPress URLs. Categories and subcategories allow you to sort content on your website. They also allow your users to easily browse the topics they are most interested in. In this article, we will show you how to include category and subcategory in WordPress URLs.

最近,我们的一位读者问我们如何在WordPress URL中包括类别和子类别。 类别和子类别使您可以对网站上的内容进行排序。 它们还使您的用户可以轻松浏览他们最感兴趣的主题。在本文中,我们将向您展示如何在WordPress URL中包括类别和子类别。

How to Include Category and Subcategory in WordPress URLs
在WordPress中包括类别到SEO友好URL (Including Category to SEO Friendly URLs in WordPress)

WordPress comes with two built-in taxonomies to sort your content. They are called categories and tags.

WordPress带有两个内置的分类法来对您的内容进行排序。 它们称为类别和标签

Categories are typically used for more broader topics and can have subcategories. See our guide on how to add categories and subcategories in WordPress.

类别通常用于更广泛的主题,并且可以包含子类别。 请参阅有关如何在WordPress中添加类别和子类别的指南。

However, if you are using the default WordPress URL structure, then your categories and subcategories are not included in the post URLs.

但是,如果您使用默认的WordPress URL结构 ,则您的类别和子类别将不包含在发布URL中。

Some websites use categories and subcategories in WordPress URLs for their posts. For example, at WPBeginner we include category in the URLs of our posts like this:

一些网站将WordPress URL中的类别和子类别用于其帖子。 例如,在WPBeginner中,我们在帖子的URL中包括以下类别:

https://www.wpbeginner.com/plugins/7-best-wordpress-backup-plugins-compared-pros-and-cons/

https://www.wpbeginner.com/plugins/7-best-wordpress-backup-plugins-compared-pros-and-cons/

Some websites that use subcategories display both parent and child categories in the URL.

一些使用子类别的网站在URL中同时显示父类别和子类别。

http://example.com/news/national/article-title-here/

http://example.com/news/national/article-title-here/

In this example, news is the parent category and national is the child category.

在此示例中,新闻是父类别,国家是子类别。

Including category or subcategory to your post URLs makes them more user-friendly. It matches the breadcrumb navigation on your site and it includes more keywords and text which is also helpful for SEO.

在您的帖子网址中包含类别或子类别,使它们更加用户友好。 它与您网站上的导航导航相匹配,并且包含更多的关键字和文本,对于SEO也很有帮助。

Having said that, let’s see how to easily add category and subcategory in WordPress URLs.

话虽如此,让我们看看如何轻松地在WordPress URL中添加类别和子类别。

在WordPress帖子URL中添加类别和子类别 (Adding Category and Subcategory in WordPress Post URLs)

First, you need to visit Settings » Permalinks page in your WrodPress admin. There you need to click on the ‘custom structure’ option under common settings area.

首先,您需要在WrodPress管理员中访问“设置”»“永久链接”页面。 在那里,您需要单击常规设置区域下的“自定义结构”选项。

Adding category to WordPress post URLs

Next, you need to add /%category%/%postname%/ in the field next to custom structure.

接下来,您需要在自定义结构旁边的字段中添加/%category%/%postname%/

After that, don’t forget to click on the save changes button to store your settings.

之后,别忘了单击“保存更改”按钮来存储您的设置。

That’s all WordPress will now start including category and subcategory in WordPress URLs. You can see this in action by editing a post or creating a new one.

到此为止,所有WordPress都将开始在WordPress URL中包括类别和子类别。 您可以通过编辑帖子或创建新帖子来查看实际情况。

File that post under a category (and subcategory if you use them) and click on the update button.

将帖子张贴在一个类别(如果使用的话,还包含子类别)下,然后单击“更新”按钮。

Category and subcategory in blog post URL

You will notice category and subcategory included in the post’s permalinks.

您会注意到帖子的永久链接中包含了类别和子类别。

使用多个类别或子类别 (Using Multiple Categories or Subcategories)

Let’s suppose you file your blog posts into multiple categories or subcategories. WordPress will only include one category and one subcategory in the URL. If you didn’t choose a subcategory, then it will only show one parent category.

假设您将博客文章分为多个类别或子类别。 WordPress在URL中仅包含一个类别和一个子类别。 如果您没有选择子类别,那么它将仅显示一个父类别。

WordPress chooses the category alphabetically. For example, if you file a post in Apple and Technology categories, then WordPress will include apple in the URL because it comes first in alphabetical order.

WordPress按字母顺序选择类别。 例如,如果您在Apple和Technology类别中发布帖子,则WordPress将在URL中包含apple,因为它按字母顺序排在第一位。

http://example.com/apple/article-title-here/

http://example.com/apple/article-title-here/

If you file a post in ‘Apple’ and a subcategory under that called ‘Technology’, then it will include both of them in the URL.

如果您在“ Apple”中发布了一个帖子,并在“ Technology”下添加了一个子类别,那么它将在URL中同时包含这两个帖子。

http://example.com/apple/technology/article-title-here/

http://example.com/apple/technology/article-title-here/

If you selected a subcategory but didn’t specifically select parent category, then WordPress will still include parent category in the URL.

如果您选择了一个子类别,但没有特别选择父类别,那么WordPress仍将在URL中包括父类别。

Another scenario is when you have a parent category, subcategory, and a sub-subcategory. WordPress will include all three of them in the URL.

另一种情况是您具有父类别,子类别和子子类别。 WordPress将在URL中包括所有这三个。

http://example.com/apple/technology/events/article-title-here/

http://example.com/apple/technology/events/article-title-here/

We hope this article helped you learn how to include category and subcategory in WordPress URLs. You may also want to see our step by step WordPress seo guide for beginners.

我们希望本文能帮助您学习如何在WordPress URL中包括类别和子类别。 您可能还想看看我们针对初学者的WordPress SEO分步指南

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-include-category-and-subcategory-in-wordpress-urls/

url wordpress

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值