如何用简码在网站上展示产品

在 WooCommerce 中,使用简码(shortcode)可以在首页或其他页面上显示特定类目或特定产品。下面就给大家介绍几种常见的使用形式:

1. 显示特定分类的产品

需要在简码中添加 category 参数。

[products limit="8" columns="4" category="category-slug"]
  • limit: 显示的产品数量(例如 8)。
  • columns: 每行显示的列数(例如 4)。
  • category: 你商城产品分类(在 WooCommerce 的“产品 > 分类”中找到对应类别的 slug)。

例如,若要显示“服装”类别的 8 个产品,假设分类 slug 为 clothing,简码如下:

[products limit="8" columns="4" category="clothing"]

如果需要显示多个类别,可以用英文逗号分隔多个 slug:

[products limit="8" columns="4" category="clothing,accessories"]

2. 显示具体产品

如果想展示特定产品,可以使用 ids 参数,指定产品的 ID。产品 ID 可以在 WooCommerce 的“产品”管理页面中找到。

[products limit="8" columns="4" ids="22,45,67"]
  • ids: 产品的具体 ID,多个 ID 用逗号分隔。

3. 显示特色产品

特色产品是在 WooCommerce 产品编辑页面中标记为“特色”的产品。

[products limit="8" columns="4" visibility="featured"] 
  • visibility=”featured”: 只显示被标记为特色的产品。
  • 示例效果:显示 8 个特色产品,每行 4 列。

4. 其他常用参数

以下是 [products] 简码的一些其他常用参数,可根据需要组合使用:

  • orderby: 排序方式,例如 date(按日期)、price(按价格)、popularity(按销量)、rating(按评分)。示例:orderby=”price” order=”ASC”。
  • order: 排序顺序,ASC(升序)或 DESC(降序)。
  • on_sale: 显示促销中的产品,设置为 true。示例:[products limit=”8″ columns=”4″ on_sale=”true”]。
  • tag: 显示带有特定标签的产品,指定标签 slug。示例:[products tag=”summer-sale”]。

5. 组合使用

可以组合多个参数使用,例如,显示“服装”类别中 8 个促销中的特色产品。

[products limit="8" columns="4" category="clothing" visibility="featured" on_sale="true"]

6. 简码没有生效原因

  • 检查分类 slug 或产品 ID 是否正确。
  • 确保 WooCommerce 插件已启用且产品数据已正确配置。
  • 查看页面是否有缓存,尝试清除缓存。

© 文章版权归白小菌所有,🫰欢迎转发分享。未经允许请勿抄袭转载。

留下评论

您的邮箱地址不会被公开。 必填项已用 * 标注