Repo Advanced

Categories and Tags

Like you know it from standard posts, you can use categories and tags with Repo items.

In this example, the Jedi Interceptor is settled in the LEGO category “Star Wars” and I tagged it with “spaceship” and “yellow”.

ASA 2 Repo categories and tags

Now you can use ASA 2‘s shortcode [asa2_smart_collection] to dynamically embed items on your pages based on categories and tags.

For example, if you want to embed three items from the category “Star Wars” tagged with “spaceship”, you could use the following shortcode:

[asa2_smart_collection cat_slug="starwars" tag="spaceship" limit="3"]

You want to show 10 “yellow” tagged items in a random order? Use this shortcode:

[asa2_smart_collection tag="yellow" limit="10" orderby="random"]

Shortcode [asa2_smart_collection]

The shortcode [asa2_smart_collection] is one of the most powerful features of ASA 2. With it you can create dynamic queries to your ASA 2 Repo with filters for many relevant product properties.

For example, to display only Star Wars spaceships having a better average rating than 4, use this shortcode:

[asa2_smart_collection cat_slug="starwars" tag="spaceship" rating_gt="4"]

You can also add a price filter. This example would only display Repo items with a main price lower than 100.

[asa2_smart_collection cat_slug="starwars" tag="spaceship" rating_gt="4" main_price_lt="100"]

Check the shortcode page [asa2_smart_collection] for a detailed list of all available options.

Custom Fields

Another powerful feature is the use of Custom Fields with your Repo items.

On http://asa2-demo.de/custom-fields/ I have setup Custom Fields for my personal rating and my recommendation on a product. The easiest way to create these, is with the plugin Advanced Custom Fields (ACF). When you setup a new field group for Repo items in ACF, just set the rule to “Post Type - is equal to - asa_repo”:

ASA 2 Repo ACF location

Then I setup the rating field with field type “Number”, field name “my_rating”, minimum value “1” and maximum value “10”, like shown in this screenshot:

ASA 2 Repo ACF field

The second field “recommendation” I setup with field type “Radio Button” and three choices you can see in this screenshot:

ASA 2 Repo ACF field

When I enter the edit page of a Repo item it looks like this:

ASA 2 Repo ACF field

I can enter a personal rating from 1 to 10 and check the radion button “Yes” if I would recommend the product. This data can then be used in ASA 2 templates.

In your templates you can use all custom fields with this special placeholder:

{{ repo_custom_field_* }}

You just have to replace the “*” with the name of your custom field, like for this example to retrieve the value of custom field “my_rating”:

{{ repo_custom_field_my_rating }}

Note

Learn more about all available ASA 2 Placeholders.

Now, to display my personal rating only if I have set a value, I use this template code:

{% if repo_custom_field_my_rating is not empty %}<p>My personal rating: {{ repo_custom_field_my_rating }}</p>{% endif %}

And to show if I recommend a product:

{% if repo_custom_field_recommendation == "yes" %}<p>I recommend this product!</p>{% endif %}

Note

Learn more about ASA 2‘s Template Syntax.

Of course I could display anything instead of just text, for instance load an image with my custom rating stars or a recommendation badge etc. This is just a demonstration of what is possible with custom fields on Repo items and ASA 2‘s conditional template syntax.