We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

How do I display total entry count while limiting entries shown?

How Do I?

User fRIQeIlu's avatar
User fRIQeIlu
7 posts
2 months ago
User fRIQeIlu's avatar User fRIQeIlu

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.

       
User jdvkpNCN's avatar
User jdvkpNCN
2 posts
2 months ago
User jdvkpNCN's avatar User jdvkpNCN

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.

       
User olbp8DKG's avatar
User olbp8DKG
9 posts
2 months ago
User olbp8DKG's avatar User olbp8DKG

The Statistics module may help here (it should be installed by default):

{if count == 1} {exp:stats channel="news"} <p>Total news articles: {total_entries}</p> {/exp:stats} {/if}

       
User jdvkpNCN's avatar
User jdvkpNCN
2 posts
2 months ago
User jdvkpNCN's avatar User jdvkpNCN

@roballen Damn, missed that. 👍

       
Hop Studios's avatar
Hop Studios
483 posts
2 months ago
Hop Studios's avatar Hop Studios

absolute_results will return what you’re looking for if you have pagination enabled. Without pagination it’s the same as the limit.

       
User DhyurnTL's avatar
User DhyurnTL
1 posts
2 months ago
User DhyurnTL's avatar User DhyurnTL

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 🐾

       
User fRIQeIlu's avatar
User fRIQeIlu
7 posts
2 months ago
User fRIQeIlu's avatar User fRIQeIlu

Ah, forgot about the stats module

       
User fRIQeIlu's avatar
User fRIQeIlu
7 posts
2 months ago
User fRIQeIlu's avatar User fRIQeIlu

I think I’ll just use an embed @ 😉

       
User fRIQeIlu's avatar
User fRIQeIlu
7 posts
2 months ago
User fRIQeIlu's avatar User fRIQeIlu

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}

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.