0

When I display a couple of entries using the channel tag, and use the {count} var inside the entries template, I simply get 1,2,3,4 etc.

When I use a conditional to filter entries like so:

{exp:channel:entries channel='artworks'}
    {if "{specifications}{type}{/specifications}" == "Painting"}
        {count}
    {/if}
{/exp:channel:entries}

Now I successfully filter my entries to only display those entries that match my criteria, however, my count var renders as (eg) 4,8.

I would like to have a variable that renders as 1,2,3 etc. So the count var should only count the rendered entries.

Ho to get this to work?

  • What kind of fieldtype is {specifications}? – Siebird Jan 21 '14 at 16:06
0

You're not really filtering your entries - you're simply showing some content conditionally. Filtering would happen at the query level - if specifications were a Grid field, then you could do:

{exp:channel:entries channel='artworks' search:specifications="Painting"}

Then {count} would work as you expected.

But if specifications is a Relationship field, this won't work. You'll need to resort to some PHP (which will need to be enabled for this specific template).

<?php $count = 1; ?>
{exp:channel:entries channel='artworks'}
    {if "{specifications}{type}{/specifications}" == "Painting"}
        <?php echo $count; $count++; ?>
    {/if}
{/exp:channel:entries}
| improve this answer | |
  • I actually didn't need to use your php method. search:specifications="Painting" was sufficient. Specifications is a Matrix field containing (among others) a select dropdown containing "Painting, Sketch, Study etc" – Louis K Jan 22 '14 at 9:29

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.