问题
I'm wondering if there are any specific "variables" I can use to ask the BigCartel database to generate products from one of the categories you can specify within your inventory?
(Ex: I would like to create a "Featured Items" section that will showcase 4 products from my T-Shirts category, a separate section for Patches, Crewnecks, Koozies, etc.)
I know you can use variables to ask the database to generate all kinds of information (ex: product title, product image, price, etc.), but I cannot seem to find one that will allow you to ask for products of a specific category.
Any help would be most appreciated. Thanks so much!
回答1:
Use a for
loop to retrieve products from specific categories (along with limit
if you only want to show 4 products) like so:
{% for product in categories.accessories.products limit:4 %}
<p>{{ product.name }}: {{ product.price }}</p>
{% endfor %}
Replace "accessories" with whatever permalink represents the category you're trying to pull from and you're all set.
来源:https://stackoverflow.com/questions/39479456/how-to-use-bigcartel-variables-to-call-different-product-categories