如何在WordPress导航菜单中添加帖子类型存档

Recently, one of our readers asked if it was possible to add a link to custom post type archive pages in WordPress navigation menus. An archive page in WordPress displays a list of all posts under a specific post type, category, or tag. In this article, we will show you how to add post type archive in WordPress navigation menus.

最近,我们的一位读者询问是否可以在WordPress导航菜单中添加指向自定义帖子类型存档页面的链接。 WordPress中的存档页面显示特定帖子类型,类别或标签下所有帖子的列表。 在本文中,我们将向您展示如何在WordPress导航菜单中添加帖子类型档案。

How to add custom post type archive link in navigation menus
WordPress中的自定义帖子类型档案 (Custom Post Type Archives in WordPress)

In WordPress, the term ‘Archives’ is used for a list of entries from a post type or taxonomy (like categories and tags).

在WordPress中,术语“存档”用于表示帖子类型分类法中的条目列表(例如类别和标签 )。

If archives are enabled for a custom post type, then you can display them on your website. Typically, the URL of your custom post type archive page is in this format:

如果为自定义帖子类型启用了存档,则可以将其显示在您的网站上。 通常,自定义帖子类型存档页面的URL格式如下:

http://example.com/post-type-slug/

http://example.com/post-type-slug/

Post type slug is the nice name for your custom post type.

帖子类型slug是自定义帖子类型的好名字。

For example, we have a custom post type called ‘Deals’, and you can view its archive page at a URL like this:

例如,我们有一个名为“ Deals”的自定义帖子类型,您可以通过以下网址查看其存档页面:

https://www.wpbeginner.com/deals/

https://www.wpbeginner.com/deals/

You can place a link to the archive page of your custom post type in your site’s navigation menus. This will allow your users to see all past entries posted in that post type on a single page.

您可以在网站的导航菜单中放置指向自定义帖子类型的存档页面的链接。 这将使您的用户可以在单个页面上查看以该帖子类型发布的所有过去的条目。

Having said that, let’s see how to add a link to your custom post type archive page in WordPress navigation menus.

话虽如此,让我们看看如何在WordPress导航菜单中向自定义帖子类型存档页面添加链接。

在导航菜单中将链接添加到“自定义帖子类型存档”页面 (Adding Link to Custom Post Type Archive page in Navigation Menus)

First, you need to visit Appearance » Menus page. You will notice a tab for each of your custom post type in the left column.

首先,您需要访问外观»菜单页面。 您会在左栏中看到每个自定义帖子类型的标签。

Custom post type tab on navigation menus screen in WordPress

You need to click on the name of your custom post type to expand it and then click on the ‘View all’ tab.

您需要单击自定义帖子类型的名称以展开它,然后单击“查看全部”选项卡。

You will see an option for your post type archives. Check the box next to it and then click on the Add to Menu button.

您将看到帖子类型档案的一个选项。 选中它旁边的框,然后单击“添加到菜单”按钮。

Your custom post type archive will now appear as a menu item in the right column.

您的自定义帖子类型存档现在将在右侧列中显示为菜单项。

Post type archive menu item

By default, it will use your custom post type name with the word archives for the link label.

默认情况下,它将使用您的自定义帖子类型名称以及链接标签的单词archives。

You may want to change this into something easier. Click on the menu item to edit it and then change its navigation label.

您可能希望将其更改为更简单的方法。 单击菜单项进行编辑,然后更改其导航标签。

Menu label

Don’t forget to click on the save menu button to store your changes.

不要忘记单击“保存”菜单按钮来存储您的更改。

You can now visit your website to see the custom post type archive link in your navigation menu.

现在,您可以访问您的网站,以在导航菜单中查看自定义帖子类型存档链接。

Custom post type link in WordPress navigation menu

Just like posts and pages, you can also add a single entry from your post type to navigation menus.

就像帖子和页面一样 ,您也可以将帖子类型中的单个条目添加到导航菜单。

Simply select an entry and then click on add to menu button.

只需选择一个条目,然后单击添加到菜单按钮。

Adding single items from a post type to navigation menus

Don’t forget to click on the save menu button to store your changes.

不要忘记单击“保存”菜单按钮来存储您的更改。

我的自定义帖子类型未显示在菜单屏幕上 (My Custom Post Type Doesn’t Appear on Menus Screen)

Custom post types need to match some requirements in order to be displayed on Appearance » Menus page.

自定义帖子类型需要符合某些要求才能显示在“ 外观”»“菜单”页面上。

First you need to make sure that an archive page exists for your custom post type. Typically it is a URL like this:

首先,您需要确保您的自定义帖子类型存在一个存档页面。 通常,它是这样的URL:

http://example.com/movies/

http://example.com/movies/

Replace example.com with your own domain name and movies with your post type.

将example.com替换为您自己的域名,将电影替换为您的帖子类型。

If you can see entries from your post type on this page, then this means your post type supports archives but does not support other requirements.

如果您可以在此页面上看到帖子类型的条目,则表明您的帖子类型支持存档,但不支持其他要求。

Good news is that you can still add your custom post type archive page as a custom link.

好消息是,您仍然可以将自定义帖子类型存档页面添加为自定义链接。

Visit Appearance » Menus page and then click on the ‘Custom Link’ tab to expand it.

访问外观»菜单页面,然后单击“自定义链接”选项卡将其展开。

Adding a post type archive link as a custom link

Enter the URL of your custom post type archive page in the URL field and add the label you want to display in the link field.

在URL字段中输入自定义帖子类型存档页面的URL,然后在链接字段中添加要显示的标签。

Next, click on the add to menu button, and you will notice the custom link appear in the right column.

接下来,单击添加到菜单按钮,您将注意到自定义链接出现在右列中。

Custom link item in navigation menu

You can now click on the save menu button to store your changes.

现在,您可以单击“保存”菜单按钮来存储您的更改。

We hope this article helped you learn how to add post type archive in WordPress navigation menus. You may also want to see our list of 12 most useful WordPress custom post types tutorials.

我们希望本文能帮助您学习如何在WordPress导航菜单中添加帖子类型档案。 您可能还想查看我们的12个最有用的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-add-post-type-archive-in-wordpress-navigation-menus/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值