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.

Trying to style most recent 6 entries differently from others

February 27, 2012 9:06am

Subscribe [2]
  • #1 / Feb 27, 2012 9:06am

    Jonathan Morgan

    51 posts

    Hi there,

    I’m outputting an alphabetical list of entries (football clubs), but want the most recent 6 entries to have an extra class so that I can style them differently and users know that they’re new.

    I was wondering if anyone has any suggestions on how I could achieve this using native EE functionality?

    Many thanks,
    Jonathan

  • #2 / Feb 27, 2012 10:03am

    Design by Front

    106 posts

    Hey Jonathan,

    You’ll want to use the count variable with a conditional statement. So in this case:

    class="some-class{if count <= 6}-special-class{/if}"

    You may also find the total_results variable useful for identifying the last item in your list:

    {if count == total_results}
    This is the last item
    {/if}

    And similarly for the first item:

    {if count == 1}
    This is the first item
    {/if}

    Hope this helps 😊

  • #3 / Feb 27, 2012 10:16am

    Design by Front

    106 posts

    Oops, sorry, I didn’t read your post thoroughly enough! I suspect you might need to do something special here. There’s possibly a more elegant way to do this but you could use an embedded template to pass in the IDs of the 6 most recent entries. So in your main template you would have something like:

    {embed=shared/my_list {exp:channel:entries channel="your_channel" limit="6" dynamic="no" orderby="date" sort="desc"}entry_id_{count}="{entry_id}"{/exp:channel:entries}}

    Then in the “shared/my_list” template:

    <ul>
    {exp:channel:entries channel="your_channel" dynamic="no" orderby="title" sort="asc"}
    <li class="some-class{if embed:entry_id_1 == entry_id OR embed:entry_id_2 == entry_id OR embed:entry_id_3 == entry_id OR embed:entry_id_4 == entry_id OR embed:entry_id_5 == entry_id OR embed:entry_id_6 == entry_id} special-class{/if}">{title}</li>
    {/exp:channel:entries}
    </ul>

    Like I say, I doubt this is the most graceful or efficient idea but unfortunately I don’t have time just now to give it some real proper thought 😊

    either way, hope it helps!

  • #4 / Feb 27, 2012 6:20pm

    Sean C. Smith

    3818 posts

    Jonathon,

    Does the solution that Designbyfront posted work for you? I would also suggest something similar to that.

    Sean

  • #5 / Mar 05, 2012 6:27am

    Jonathan Morgan

    51 posts

    Hi guys,

    Thanks for your responses. Apologies for the delay - I got caught up in another issue. I’m going to give that a go now and let you know asap.

    Cheers!

  • #6 / Mar 05, 2012 6:45am

    Jonathan Morgan

    51 posts

    That worked perfectly - thanks Designbyfront!

  • #7 / Mar 05, 2012 7:00am

    Design by Front

    106 posts

    No worries! Glad it helped 😊

  • #8 / Mar 06, 2012 8:21pm

    Sean C. Smith

    3818 posts

    Awesome, glad you got it all working. I’m going to close out this thread, but feel free to post again when you have more questions.

    Sean

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

ExpressionEngine News!

#eecms, #events, #releases