ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Best method of displaying featured channel entry i.e. Recipe of the month

January 13, 2012 4:56am

Subscribe [4]
  • #1 / Jan 13, 2012 4:56am

    itsproof

    3 posts

    Hi, I’m relatively new to EE but am loving it. I’m a front-end designer, developer and using EE is simply a joy to use and in my opinion knocks the socks off other platforms. Anyway, these forums have been great for helping me figure out how to do a few fancy things but I’m struggling with one particular idea.

    I have a “Recipes” channel with approx 15 channel fields. One of which is a “Featured Recipe” checkbox with ‘Yes’ as the only option. The recipes page displays all entries but my idea is that when a recipe is selected as “featured” by the client it is presented as “Recipe of the month” in the top section of the page.

    You can see what I’m trying to do here: http://blackacre.itsproof.co.uk/recipes

    Currently I have the following code which works….

    {exp:channel:entries channel="recipes" dynamic="no" }
    {if featured_recipe }
    <div id="recipe-card">
    {if recipe_image_thumbnail}{recipe_image_thumbnail}{/if}
    <div class="rotm-details">
    <h4 class="title-link"><a href="http://{title_permalink=/recipes/recipe}">{title}</a></h4>
    {short_description}
    </div>
    <a href="http://{title_permalink=/recipes/recipe}" class="rotm-link">View this featured recipe</a>
    </div>
    {/if}

    The only trouble with the above is that is multiple recipes are selected as “featured” they are all displayed. I’m currently hiding them using css but this is not ideal as the html for each featured recipe in the loop still exists in the HTML. Is there a way that EE can get all featured recipes but only display the latest recipe added, i.e. one with the highest entry ID?

    Or is there another, better way to do featured entries?

    Thanks.
    Neil

  • #2 / Jan 13, 2012 10:40am

    zizther

    228 posts

    You can use limit=“1”, so change

    {exp:channel:entries channel="recipes" dynamic="no"}

    to

    {exp:channel:entries channel="recipes" dynamic="no" limit="1"}

    This will just display 1 entry. You can add orderby=“entry_id”
    Check out other ways of ordering: http://ellislab.com/expressionengine/user-guide/modules/channel/channel_entries.html#orderby

    Have you thought about using related entries, this would save the client from having to go into all the entries to select or deselect it. That way thjey could just select from the list of entries in another channel.

    An easy way to do this is using the playa add-on: http://pixelandtonic.com/playa
    Its alot for a little, but if you can make other uses of it, it is very good!

    You can set them up in EE though

  • #3 / Jan 13, 2012 11:08am

    I’d suggest using a category as your way of denoting a featured entry, not a channel field, along with limit=1.

    {exp:channel:entries channel="recipes" dynamic="no" limit="1" category="id-number-of-the-featured-category-would-go-here"}
  • #4 / Jan 14, 2012 10:56am

    Rob Allen

    3114 posts

    Another approach would be to use a custom Status to denote “Featured” recipes, benefit here is that that can be quickly looked up/identified from the Edit page.

  • #5 / Jan 14, 2012 3:47pm

    Dan Decker

    7338 posts

    Hi itsproof,

    Welcome to ExpressionEngine and the Forums, thanks for the kind words!

    As you can see, the Community is knowledgeable and friendly. Any of the suggestions they have offered here should get you what you are looking for. zither’s advice would be my preference (personally) but all the others are great as well!

    Is there anything else we can assist you with?

  • #6 / Jan 16, 2012 4:09am

    itsproof

    3 posts

    Thank you all for your suggestions. I like the idea of a custom status and being identified from the edit page. Also the “featured” category option could work too. I’ll give them both ago and see which works best for the client.

    One more thing, and forgive me as I’ve seen this as a common question but simply wonder if there is has been a simple fix for it, but what is the easiest way to show a total count of the number of entries belonging to a category and/or archive list?

    For example the recipes pages in the website http://blackacre.itsproof.co.uk/recipes, in the right hand ‘Recipe Categories’ I’d quite like to show something like Starters (3), Main Courses (5), Dessert (4)

    Is this do-able?

    I’m a front-end designer type so go as far as XHTML and CSS. Php is not my bag so if this can be done with EE’s expressions that would be great. Thanks again.

    Neil

  • #7 / Jan 16, 2012 12:00pm

    This add-on can give you the counts you’re looking for: http://devot-ee.com/add-ons/category-count

    Filtering by status is dandy, but, it will require you to rewrite all of your existing {exp:channel:entries} loops, which, by default, will only show entries where the status is “Open.”  Filtering by category shouldn’t interfere with any existing code.

  • #8 / Jan 16, 2012 2:52pm

    Matt Powell

    42 posts

    Hi. I’d be interested to know - if you adopted the limit=1 approach would the same recipe then be included in your second query further down the page? If so this might not be ideal - maybe a sticky post type of approach would work?

  • #9 / Jan 17, 2012 6:44am

    itsproof

    3 posts

    The method of adding limit=“1” to the call seemed to not show any recipes at all which is a little odd. I’m now using the featured category method to display the highlighted recipe at the top of the page which works a treat. Limit=“1” works with this method too which is great and it doesn’t interfere with the main list of recipes as this is a separate call to the recipes channel. Hope that makes sense?!

    Thanks everyone for your suggestions.

    Neil

  • #10 / Jan 17, 2012 7:25am

    Matt Powell

    42 posts

    hi neil

    could i check - does the ‘recipe of the month’ also appear in the second query? if so, is that what you wanted??

  • #11 / Jan 17, 2012 8:08am

    itsproof

    3 posts

    Hi Matt, No, the featured recipe is not shown in the second query/full list. There is however a variable in this query that says if a recipe is selected as a “Chef’s Recipe” (one written by a chef that endorses the eggs), that the recipe displays a “chef russell” banner. This was easily done by using {if recipe_author}DISPLAY BANNER{/if} but strangely the same principle didn’t work in the top instance???

    And in case you’re wondering, recipe_author was a simple custom checkbox for the recipe channel entries.

  • #12 / Jan 17, 2012 8:09am

    Matt Powell

    42 posts

    Great, thanks for that, sounds excellent.

  • #13 / Jan 20, 2012 5:30pm

    Dan Decker

    7338 posts

    Wow y’all, this took on a life of its own!

    Fantastic. To keep it alive, I’m going to move this into Community Help for now.

    If anyone needs anything else at all, please ping us in a new thread!

    Cheers!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases