群晖wordpress

Organizing WordPress posts into different categories is essential if you have many posts. That way, your visitors (and you!) can easily search and sort your posts and only see what they want.

如果您有很多帖子,则将WordPress帖子组织成不同类别至关重要。 这样,您的访问者(和您!)就可以轻松地搜索和排序您的帖子,仅查看他们想要的内容。

In this article we’ll look at how we can manage WordPress categories. We’ll begin with the description of some basic things about adding, editing or deleting a category.

在本文中,我们将研究如何管理WordPress类别。 我们将从描述有关添加,编辑或删除类别的一些基本内容开始。

Then, we’ll look at how to display a list of our categories, and how to customize this list, with the default widget that WordPress provides us.

然后,我们将研究如何使用WordPress为我们提供的默认小部件显示类别列表以及如何自定义此列表。

(Managing Categories)

WordPress give us a dedicated page for managing categories, available in the menu of the administration panel. More precisely, this page is accessible from the “Posts” submenu and is named “Categories”.

WordPress在管理面板的菜单中为我们提供了一个用于管理类别的专用页面。 更准确地说,可从“帖子”子菜单访问此页面,并将其命名为“类别”。

(Two Ways to Add a Category)

If you access this page, you can see a form on the left, named “Add New Category”. The first field in this form, labeled “Name”, is as it suggests, is the name that will appear everywhere you display the category of a post or the list of your categories on the site. The usefulness of the other fields is not necessarily obvious.

如果访问此页面,则可以在左侧看到一个名为“添加新类别”的表单。 所建议的,此表单中的第一个字段标记为“名称”,是将在您显示帖子的类别或网站上的类别列表的任何地方出现的名称。 其他领域的用处不一定很明显。

First, the “slug”. As it is described right below the field, this string is useful when you activate URL Rewriting to have readable URLs for your website’s pages. For example, let’s assume that you set “category” in the “Category base” permalinks settings (from the Settings -> Permalinks menu). Then, if you enter “my-life” into the slug of your new category, visitors can access the page listing all the posts in this category by using the URL http://example.com/category/my-life.

首先是“ sl”。 如该字段下方所述,当您激活URL重写以使网站页面具有可读的URL时,此字符串很有用。 例如,假设您在“类别库”永久链接设置中设置“类别”(从“设置”->“永久链接”菜单中)。 然后,如果您在新类别的条目中输入“ my-life”,则访问者可以使用URL http://example.com/category/my-life访问列出该类别中所有帖子的页面。

Note that, as this string is used in a URL, some rules must be respected, but you can in practice indicate whatever you want, as WordPress will automatically clean your string to make it “URL-friendly”.

请注意,由于此字符串在URL中使用,因此必须遵守一些规则,但是您可以在实践中指出所需的内容,因为WordPress会自动清除您的字符串以使其“对URL友好”。

Right after this field we find a list labeled “Parent”. This list allows you to choose one of your existing categories to be the parent of your new category. That way, you can build your own hierarchy, which is a good thing when you have several categories. For example, if you added the category “My life” and if you want to put in one category your posts about the awesome life of your goldfish, then you can create the category “My goldfish” with “My life” as a parent. It’s exactly like directories and subdirectories on your computer.

在该字段之后,我们立即找到一个标记为“父母”的列表。 此列表使您可以选择现有类别之一作为新类别的父类别。 这样,您可以构建自己的层次结构,当您具有多个类别时,这是一件好事。 例如,如果您添加了“我的生活”类别,并且想要将关于金鱼的令人敬畏的生活的帖子放在一个类别中,则可以将“我的生活”作为父项来创建“我的金鱼”类别。 就像计算机上的目录和子目录一样。

Finally, you can enter a description of your category in the last field. Not all themes use this field, so be sure that your theme does before spending time filling this in!

最后,您可以在最后一个字段中输入类别的描述。 并非所有主题都使用此字段,因此在花时间填写此主题之前,请确保您的主题已使用!

群晖WordPress 群晖wordpress使用_python

To finish with the addition of a category we can note that there is also another way to add a category: when you write a new post (or when you edit an existing one). In fact, when you choose the category where you put your post, you can find an “Add New Category” link that allows you to add a new category by simply indicating its name and, if necessary, its parent. The slug will then be its cleaned name, and its description will be empty. However, you can still edit this category and change it later.

为了完成添加类别的操作,我们可以注意到还有另一种添加类别的方法:撰写新帖子(或编辑现有帖子)。 实际上,当您选择张贴文章的类别时,可以找到“添加新类别”链接,该链接可让您通过简单地指明其名称以及必要时指示其父类别来添加新类别。 然后,该段将是其清理后的名称,并且其描述将为空。 但是,您仍然可以编辑此类别并在以后进行更改。

(Editing a Category)

It’s always possible to edit a category, to update its information. Editing a category can be done from the same page as previously, in the “Categories” submenu of the “Posts” menu.

始终可以编辑类别以更新其信息。 可以从与以前相同的页面上,在“帖子”菜单的“类别”子菜单中完成类别的编辑。

You’ll see on the right of this page the list of your categories, similar to the list of your posts in the corresponding page. By clicking the name of a category you will be redirected to another page containing a form, already pre-filled with the current information. All you have to do is modify the category you want and submit the form once you’re done.

您将在此页面的右侧看到类别列表,与相应页面中的帖子列表类似。 通过单击类别的名称,您将被重定向到另一个包含表单的页面,该表单已预先填充了当前信息。 您要做的就是修改所需的类别,并在完成后提交表单。

If you only want to change the name or the slug of a category you can also choose the “Quick Edit” option appearing when your mouse is over a category.

如果只想更改类别的名称或标签,还可以选择当鼠标悬停在类别上时出现的“快速编辑”选项。

群晖WordPress 群晖wordpress使用_群晖WordPress_02

(Deleting a Category)

Right next to the “Quick Edit” option we find the “Delete” one. If you want to delete a category, click on this link, confirm your choice, and you’re done. You can also select all the categories you want to delete and choose “Delete” in the “Bulk Actions” list. Be careful: deleting a category is not an action that can be reversed.

在“快速编辑”选项旁边,我们找到“删除”选项。 如果要删除类别,请单击此链接,确认选择,然后完成。 您还可以选择要删除的所有类别,然后在“批量操作”列表中选择“删除”。 注意:删除类别不是可以撤消的操作。

Note that deleting a category won’t delete the posts using this category. If these posts use other categories, the deleted category will just disappear from their used categories list. If they don’t use any other category, then they will fall into the default category, named “uncategorized”. Note that this is the reason why this category can’t be deleted (but you can still edit it).

请注意,删除类别不会删除使用该类别的帖子。 如果这些帖子使用其他类别,则删除的类别将从其使用的类别列表中消失。 如果他们不使用任何其他类别,则它们将属于默认类别,称为“未分类”。 请注意,这就是无法删除此类别的原因(但您仍然可以对其进行编辑)。

(A Widget to Display the Categories)

As for the Links Manager, WordPress provides us a default widget to display a list of our categories wherever we want in our theme. Let’s test it by accessing the widgets manager from the “Appearance” menu.

至于Links Manager ,WordPress为我们提供了一个默认的小部件,可以在主题中的任意位置显示我们类别的列表。 让我们通过从“外观”菜单访问小部件管理器来对其进行测试。

Simply named “Categories”, this widget allows us to customize its display with four settings. By default, the title of this widget is set to “Categories”, but you can change it by entering the title of your choice in the “Title” field.

简单地命名为“类别”,此小部件使我们可以使用四个设置来自定义其显示。 默认情况下,此小部件的标题设置为“类别”,但是您可以通过在“标题”字段中输入所选标题来进行更改。

The three other settings are checkboxes that allow you to customize the list of categories. Note that, whatever you choose in these options, only the categories that contain at least one post are shown (if we forget the “parent effect” explained below).

其他三个设置是复选框,可用于自定义类别列表。 请注意,无论您在这些选项中选择什么,都只会显示至少包含一个帖子的类别(如果我们忘记了下面解释的“父效”)。

To explain the “parent effect” we begin with the last option: “Show hierarchy”. This option is useful if you set some categories as parents of others (see the glorious example of your life and your goldfish above). As you may guess, by activating this option, WordPress will display the exact hierarchy of your categories.

为了解释“父母效应”,我们从最后一个选项开始:“显示层次结构”。 如果您将某些类别设置为其他类别的父项,则此选项很有用(请参见上面有关您的生活和金鱼的光辉榜样)。 您可能会猜到,通过激活此选项,WordPress将显示您类别的确切层次。

Without this option, all of your categories are displayed in one column, without any relation between them.

如果没有此选项,则所有类别都显示在一个列中,它们之间没有任何关系。

群晖WordPress 群晖wordpress使用_java_03

With this option activated, the hierarchy is shown, with nested lists.

激活此选项后,将显示带有嵌套列表的层次结构。

群晖WordPress 群晖wordpress使用_群晖WordPress_04

When you activate this option you must think about an effect: parents are shown, even if they do not contain any posts themselves. For example, the two screenshots above were taken with the same configuration, with the same posts and categories. The “Parent” category does not contain any post by itself, but its children do, so WordPress displays it in the list, to show the hierarchy. It is an expected effect, but it’s always a good thing to see how it works.

激活此选项时,您必须考虑一种效果:显示父母,即使他们自己不包含任何帖子。 例如,上面的两个屏幕截图是使用相同的配置,相同的帖子和类别拍摄的。 “父项”类别本身不包含任何帖子,但其子类包含任何帖子,因此WordPress将其显示在列表中以显示层次结构。 这是预期的效果,但是了解其工作原理始终是一件好事。

The second option, labeled “Show post counts”, is relatively clear: it adds, between parenthesis, the number of posts contained in each category.

第二个选项标记为“显示帖子数”,它相对清晰:在括号之间增加了每个类别中包含的帖子数。

群晖WordPress 群晖wordpress使用_java_05

Note, again, the “parent effect”: a parent category shows the sum of all of its children’s counts.

再次注意“父效应”:父类别显示其所有子项计数的总和。

Finally, the first option: “Display as dropdown”, which allows you to display the list of categories as a dropdown list. This option is particularly useful if you have a lot of categories. Your visitors have to open the list and select the category they want to see. Then, automatically, WordPress will redirect them to the right page.

最后,第一个选项:“显示为下拉列表”,它使您可以将类别列表显示为下拉列表。 如果您有很多类别,则此选项特别有用。 您的访客必须打开列表,然后选择他们要查看的类别。 然后,WordPress将自动将它们重定向到正确的页面。

Note that this option is compatible with the two others: hierarchy and posts counts can still be shown in the dropdown list.

请注意,此选项与其他两个选项兼容:层次结构和职位数仍可以在下拉列表中显示。

群晖WordPress 群晖wordpress使用_数据库_06

(In Conclusion)

Categories are important to help organize your website. Now that we’ve seen how to add, edit and delete a category, you have no excuse to not sort your posts!

类别对于帮助组织您的网站很重要。 既然我们已经了解了如何添加,编辑和删除类别,那么您就没有理由不对帖子进行排序!

If knowing how to manage categories is important, as a developer, the most important part comes with the question: how to retrieve these categories? How to list them? How to display information about one particular category?

如果知道如何管理类别很重要,那么作为开发人员,最重要的部分是问题:如何检索这些类别? 如何列出它们? 如何显示有关一个特定类别的信息?

The answer to this question can be found in using the WordPress Categories API, an API grouping some functions that can do the things we just listed. The good news is that the Categories API is the topic of our next article!

这个问题的答案可以在使用WordPress Categories API中找到,该API将一些可以完成我们刚刚列出的功能的函数进行分组。 好消息是,类别API是我们下一篇文章的主题!

翻译自: https://www.sitepoint.com/wordpress-categories-explained/

群晖wordpress