I want to get the current article count with a single article view. So I've I'm currently viewing the fifth of ten articles, it will output '5'.

If I do this:

{exp:channel:entries channel="articles" sort="asc" limit="1"}

{count}

{/exp:channel:entries}

This always evaluates to 1, as it's the single entry view.

I've tried {absolute_count} but this provides the same result.

Any ideas, I'm open to using {query} tags but I can't work it out.

Have you tried including 'Dynamic="no"' ie

{exp:channel:entries channel="articles" sort="asc" limit="1" dynamic="no"}

https://docs.expressionengine.com/v3/channel/channel_entries.html#dynamic

  • Yes, but that just reutns everything in the channel. – tigercore Nov 6 at 16:51

There is no built in way to do this.

You could, however, do this by calling an embed that you pass the entry ID to, loop through all the articles - and when the entry id of the loop matches the embedded entry id, then you have your count. Keep in mind that the more entries in the channel, the more overhead you'll have looping through them all.

So...your single entry template would look something like the following...

{exp:channel:entries channel="articles" limit="1"}
    {embed="embeds/_get-entry-count" entry_id="{entry_id}"}
{/exp:channel:entries}

Then, in your embed...

{exp:channel:entries channel="articles" sort="asc"}
    {if entry_id == embed:entry_id}
        {count}
    {/if}
{/exp:channel:entries}

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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