简体   繁体   English

WordPress-如何多次使用内容?

[英]WordPress - How can I use content multiple times?

I have built a WordPress website with a custom theme. 我建立了一个带有自定义主题的WordPress网站。

Now I want to add a list of prices. 现在,我想添加一个价格清单。 I need to be able to group multiple prices together, and the most important thing: I want to be able to show them on multiple pages. 我需要能够将多个价格分组在一起,最重要的是:我希望能够在多个页面上显示它们。 So in steps: 因此,分步进行:

  • Make a list with text items in the Wordpress admin 在Wordpress管理员中列出文本项
  • group some of those text items together 将其中一些文本项组合在一起
  • assign groups to multiple pages to show them there( so on a page is a list where you can checkmark which group you want to show there ) 将组分配给多个页面以在其中显示它们( 所以在页面上是一个列表,您可以在其中选中要在其中显示的组

What am I looking for here? 我在这里找什么?

If your price list is dynamic and count many rows, it's probably better to store it in database. 如果您的价目表是动态的并且计数很多行,最好将其存储在数据库中。 When it comes to add custom data types to Wordpress, my favourite plugin is Pods . 在向Wordpress添加自定义数据类型时,我最喜欢的插件是Pods

It allow you to easily create and display custom post types and taxonomies, create settings page, display your data using templates, and complex queries, etc. 它使您可以轻松创建和显示自定义帖子类型和分类,创建设置页面,使用模板显示数据以及复杂查询等。

Edit : 编辑:

I don't know ACF, but it seems it's quite different from Pods : ACF is for having new fields types. 我不知道ACF,但似乎与Pods完全不同:ACF用于拥有新的字段类型。 Pods is for Custom Post Types. 窗格用于自定义帖子类型。 In your case, I would use Pods, following this procedure : 在您的情况下,我将按照以下步骤使用Pod:

  1. Create two CPTs : Price and PriceGroup 创建两个CPT:Price和PriceGroup
  2. Assign prices to price groups. 将价格分配给价格组。
  3. Create a Pod template for price groups that display all related prices (and any information you need) 为价格组创建一个Pod模板,以显示所有相关价格(以及您需要的任何信息)
  4. Include these template in specific wordpress pages, using pods shortcode. 使用pod简码将这些模板包括在特定的wordpress页面中。

For step 4, here is an example of a Pods shortcode you could include in a Wordpress Page: 对于第4步,这是您可以在Wordpress页面中包含的Pods简码示例:

[pods name="pricegroup" where="t.post_title = 'GroupToDisplay'" template="pricegroup-template"]

Your client can use this shortcode in any page or widget. 您的客户可以在任何页面或窗口小部件中使用此短代码。 The only thing that is needed is to replace GroupToDisplay with the actual group you want to display. 唯一需要做的就是用要显示的实际组替换GroupToDisplay

If you don't want your client to see this shortcode, and want something even simpler, a good option would be to create a custom shortcode that will, under the hoods, call pods shortcode. 如果您不希望客户看到此短代码,并且想要更简单的方法,一个不错的选择是创建一个自定义的短代码,该代码将在幕后调用pods短代码。 Then you will end up with something like : 然后,您将得到类似以下内容:

[pricegroup title="GroupToDisplay"]

您正在寻找的是自定义分类法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM