7

I would like to display the total number of entries for a channel and nothing else is required to be displayed.

Is there a more efficient way to do this than the following?

{exp:channel:entries channel="products"}
  {if count == total_results}
    {count}
  {/if}
{/exp:channel:entries}

2 Answers 2

9

Use the built-in Stats module:

{exp:stats channel="products"}{total_entries}{/exp:stats}

Or the Query module:

{exp:query sql="SELECT total_entries FROM exp_channels WHERE channel_name = 'products'"} 
{total_entries} 
{/exp:query}

http://ellislab.com/expressionengine/user-guide/modules/statistics/index.html#total-entries

7

From performance view is better to use query for this:

{exp:query sql="SELECT count(*) as total_results FROM exmx_channel_titles WHERE channel_id = '2' "} 
total results: {total_results} 
{/exp:query}
2
  • I don't believe the count is necessary because the table exp_channels already has this data on column total_entries.
    – Sobral
    Commented Nov 17, 2013 at 2:38
  • 1
    agree. At the same time if mysql with MyISAM, the COUNT number is stored in db, so it doesn't count all rows each time you try to count all rows and it will be not diff in performance.
    – Max Lazar
    Commented Nov 17, 2013 at 12:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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