Using version 2.5.3 of ExpressionEngine, I have a list of products displayed by category, but I need the premium products among this list being featured with a small star image. How do you call conditionally this little stars besides the {title}?
At the moment this code shows stars for all products and that is not ideal.
<ol class="voices-list">
{exp:channel:entries channel="product" orderby="title" sort="asc" category="2&6" dynamic="no"}
<li><a href="{page_url}">{title}<img class="feature_icon medium" src="{root_url}img/audio/smallstar.png" alt="star"></a></li>
{/exp:channel:entries}
</ol>
I need your help, please.
Conditional Formatting (CF) is a tool that allows you to apply formats to a cell or range of cells, and have that formatting change depending on the value of the cell or the value of a formula. For example, you can have a cell appear bold only when the value of the cell is greater than 100.
Conditional formatting can help make patterns and trends in your data more apparent. To use it, you create rules that determine the format of cells based on their values, such as the following monthly temperature data with cell colors tied to cell values.
Best to set up a new checkbox field named "is_premium" with the value set to "y".
Next, edit each premium product entry and check the box and save.
Finally, in your template use this conditional. {if is_premium == "y"}add star code{/if}
I like the approach shown in the answer posted by @MediaGirl and have used it many times.
An alternative approach is to handle it with a custom status rather than a custom field, if only to have the ability on the main edit screen to quickly and easily see and sort the list by "premium" (Zenbu could add the custom field to the edit screen, of course). The conditional would be similar, and of course the entries loop would need to have the status param of "open|premium".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With