Is there a way to display the total count of entries for a channel while limiting the number of entries that is shown? I saw this posted online (below), but it doesn’t work.
{exp:channel:entries channel="news" limit="5"}
{if count == 1}
Total News Articles: {total_results}
{/if}
<div class="news-item">
<h3>{title}</h3>
{excerpt}
</div>
{/exp:channel:entries}So, in this case, I would want the total results to show like 20, but it currently says 5.
Can’t see anything in the docs for the channel entries tag that returns the number of entries in the channel - which definitely feels like an omission. The right place for it might be in the {exp:channel:info} tag (as well as maybe in the channel entries tag).
A workaround might be to take out your limit attribute, so it returns the entire channel, and then use {absolute_results} as your value. (Not sure how {total_results} is different from that.)
Then, within the loop, you could use a comparison with {count} or {absolute_count} to limit what’s actually processed. It’s inefficient, obv., because it pulls the entire channel from the DB, but if it’s not a huge channel it would be okay.
Put the whole of the channel entries into a layout array and save the count as part of that, then when you replay the layout array put in a limit of 5 to get the first five. e.g.
{exp:channel:entries channel="news"}
{if count == 1}
{layout:set name="total"}{total_results}{/layout:set}
{/if}
{layout:set:append name="array-title"}{title}{/layout:set:append}
{layout:set:append name="array-excerpt"}{excerpt}{/layout:set:append}
{/exp:channel:entries}
and then in a later template layout:
{layout:array-title limit="5"}
{if count == 1}
<p>Total News Articles: {layout:total}</p>
{/if}
<div class="news-item">
<h3>{value}</h3>
<p>{layout:array-excerpt index="{index}"}</p>
</div>
{/layout:array-title}
HTH 🐾
Thanks @hopstudios - {absolute_results} works by simply adding paginate="hidden" to the parameters
{exp:channel:entries channel="news" limit="5" paginate="hidden"}
{if count == 1}
<p>Total News Articles: {absolute_results}</p>
{/if}
<div class="news-item">
<h3>{title}</h3>
</div>
{/exp:channel:entries}
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.