简体   繁体   中英

WordPress - How can I use content multiple times?

I have built a WordPress website with a custom theme.

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
  • 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 .

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. Pods is for Custom Post Types. In your case, I would use Pods, following this procedure :

  1. Create two CPTs : Price and 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)
  4. Include these template in specific wordpress pages, using pods shortcode.

For step 4, here is an example of a Pods shortcode you could include in a Wordpress Page:

[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.

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. Then you will end up with something like :

[pricegroup title="GroupToDisplay"]

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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