1

I'm trying to find a way to highlight the 10 most recent entries within an alphabetically sorted list of entries from a particular channel.

I don't wish to change the order of the entries, just have the ability to put some custom markup around the most recent ones.

Is there a simple way to do that or am I going to need to use a custom query instead of using channel:entries tag pair?

I'm currently thinking along the lines of having to do a query to get the entry IDs of the most recent 10 entries, storing those entry IDs and comparing them to the entry IDs when outputting my full list.

There's got to be an add-on for this though right?!

2

Try to use embed to set and pass ahead a variable:

{embed="template_group/.entries-list" eleventh="{exp:channel:entries offset='10'}{edit_date format='%U'}{exp:channel:entries}"}

On the embed template:

{exp:channel:entries}
    {if {edit_date format="%U"} < {embed:eleventh} }
        <custom markup>
    {/if}
        default markup (...)
    {if {edit_date format="%U"} < {embed:eleventh} }
        </custom markup>
    {/if}
{/exp:channel:entries}
| improve this answer | |
  • Because that would simply mark up the first 10 results that are displayed. If I'm displaying them alphabetically it won't highlight the 10 most recent, it will highlight the first 10 shown. I need to mark up the most recent regardless of the order they are displayed in. – foamcow May 19 '13 at 11:53
  • I'm sorry! My bad! – Robson Sobral May 19 '13 at 12:56
  • 1
    I fixed my answer. I think it's easier than using an addon, even Stash. – Robson Sobral May 19 '13 at 19:40
2

You can probably do this with Stash.

I haven't tested this code, but it should work.

First, output/stash the entries by date.

{exp:channel:entries orderby="date" ...}
  {exp:stash:set_list name="entries"}
    {stash:title}{title}{/stash:title}
    {stash:is_recent}{if count < 11}true{/if}{/stash:is_recent}
  {/exp:stash:set_list}
{/exp:channel:entries}

Then instead, sort appropriately using the stash output.

<ul>
{exp:stash:get_list name="entries" orderby="title" sort="asc"}
  <li {if is_recent}class="recent"{/if}>
    {title}
  </li>
{/exp:stash:get_list}
</ul>
| improve this answer | |
  • I was thinking Stash might be involved. Will give this a try asap. – foamcow May 19 '13 at 16:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.