Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to apply images conditionally using entries and categories?

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.

like image 896
Sergio Acosta Avatar asked Nov 04 '12 14:11

Sergio Acosta


People also ask

What is conditional formatting with example?

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.

How does conditional formatting work in Excel?

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.


2 Answers

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}

like image 129
Anna_MediaGirl Avatar answered Dec 11 '22 09:12

Anna_MediaGirl


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

like image 35
Jean St-Amand Avatar answered Dec 11 '22 11:12

Jean St-Amand