wordpress页面_如何让用户过滤WordPress中的帖子和页面

wordpress页面

Do you want to allow users to filter posts and pages on your WordPress site? Recently, one of our users asked us how to add filters to their WordPress site allowing users to filter posts by category, tags, post types, etc. In this article, we will show you how to let users filter posts and pages in WordPress.

是否要允许用户过滤WordPress网站上的帖子和页面? 最近,我们的一位用户问我们如何在WordPress网站上添加过滤器,从而允许用户按类别,标签,帖子类型等过滤帖子。在本文中,我们将向您展示如何让用户在WordPress中过滤帖子和页面。

How to Let Users Filter Posts and Pages in WordPress
为什么要让用户过滤WordPress中的帖子和页面? (Why Let Users Filter Posts and Pages in WordPress?)

By default, WordPress comes with categories and tags as a way for you to sort content into topics and for your users to easily find it.

默认情况下,WordPress带有类别和标签 ,这是一种将内容分类为主题并使用户轻松找到内容的方法。

However, users can only view one category, tag, or archive page at a time and it will only show one post type.

但是,用户一次只能查看一个类别,标签或存档页面,并且只会显示一种帖子类型

What if you wanted users to be able to filter content in more than one category or tag? How about allowing users to view posts, pages, and custom post types at the same time?

如果您希望用户能够过滤多个类别或标签中的内容,该怎么办? 如何允许用户同时查看帖子,页面和自定义帖子类型

This kind of filtering can be particularly helpful when you have a lot of content, and you want users to filter it according to their own preferences.

当您有很多内容,并且希望用户根据自己的喜好对其进行过滤时,这种过滤特别有用。

Having said that, let’s take a look at how to easily let users filter posts and pages in WordPress.

话虽如此,让我们看一下如何轻松地让用户过滤WordPress中的帖子和页面。

影片教学 (Video Tutorial)

演示地址

If you don’t like the video or need more instructions, then continue reading.

如果您不喜欢该视频或需要更多说明,请继续阅读。

允许用户轻松过滤帖子和页面 (Allowing Users to Easily Filter Posts and Pages)

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

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

Upon activation, the plugin will add a new menu item labeled Search & Filter to your WordPress admin bar. Clicking on it will take you to the plugin’s usage page with detailed documentation on how to use the plugin.

激活后,该插件将在您的WordPress管理栏中添加一个名为Search&Filter的新菜单项。 单击它会带您进入插件的使用页面,其中包含有关如何使用该插件的详细文档。

Search & Filter plugin documentation

Search & Filter plugin comes with a shortcode which accepts different parameters to display the filtering options. You can use this shortcode in a post, page, or inside a text widget.

Search&Filter插件带有一个短代码 ,该短代码接受不同的参数以显示过滤选项。 您可以在帖子,页面或文本小部件内使用此短代码。

[searchandfilter fields="search,category,post_tag"]

You can also use the shortcode as a template tag in your WordPress theme files like this:

您还可以在您的WordPress主题文件中使用简码作为模板标签,如下所示:

<?php echo do_shortcode('[searchandfilter fields="search,category,post_tag"]'); ?>

This will display the filtering options with search, category, and tags fields.

这将显示带有搜索,类别和标签字段的过滤选项。

Filter posts by category and tags

By default the plugin accepts search, taxonomy, post_type, and post_date as fields.

默认情况下,插件接受搜索,分类法,post_type和post_date作为字段。

Let’s take a look at another example. This time we will include category, tags, post types, and date fields.

让我们看另一个例子。 这次我们将包括类别,标签,帖子类型和日期字段。

You will need to use the shortcode like this:

您将需要使用以下简短代码:


[searchandfilter fields="search,category,post_tag,post_types,post_date"]

Here is how it would look:

外观如下:

Adding all fields to the filter

Now instead of using drop down select field, you can also use checkboxes and add labels for each field. To do that, you will need to add two more parameters to the shortcode.

现在,除了使用下拉选择字段,您还可以使用复选框并为每个字段添加标签。 为此,您需要在简码中再添加两个参数。

If you use a separate page to display your blog posts, then you can add this shortcode to the page.

如果使用单独的页面显示博客文章,则可以将此简码添加到页面中。


[searchandfilter headings="Select categories:" types="checkbox" fields="category"]

Allowing users to select multiple items in the filter using checkbox

If you are using multiple fields, types, and headings, then you need to make sure that items are in the same order for each parameter.

如果使用多个字段,类型和标题,则需要确保每个参数的项目顺序相同。

Let’s see another example. This time we are adding category, tags, and post type fields with different headings and form field types.

让我们来看另一个例子。 这次,我们将添加具有不同标题和表单字段类型的类别,标签和帖子类型字段。


[searchandfilter headings="Post type, Category, Tag" types="checkbox, select, select" fields="post_types,category,post_tag"]

This is how it would appear on your site:

它将显示在您的网站上:

Advance filtering with headings and different field types

Please refer to plugin’s documentation page for more ways to use the shortcode.

请参阅插件的文档页面以获取更多使用短代码的方法。

You can also use these shortcodes inside a text widget. If the shortcode doesn’t work in your text widget, then please see our guide on how to use shortcodes in your WordPress sidebar widgets.

您也可以在文本窗口小部件内使用这些短代码。 如果该短代码在您的文本小部件中不起作用,那么请参阅有关如何在WordPress边栏小部件中使用短代码的指南。

We hope this article helped you learn how to let users filter posts and pages in WordPress. You may also want to see these actionable tips to drive traffic to your WordPress site.

我们希望本文能帮助您学习如何让用户过滤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/plugins/how-to-let-users-filter-posts-and-pages-in-wordpress/

wordpress页面

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值