I want to add a different class and fields to the 1st and 2nd entries produced from the channel entries call.

I then want the rest of the entries on the page to be the same style, that style should then continue in the pagination, the 1st and 2nd entries should not be styled differently on the pagination pages.

I have tried using {if count == '1'} and {if count == '2'}, and {if absolute_count == '1'} and {if absolute_count == '2'}, but the pagination also styled the first and second entry.

My scenario is the first entry will be large than the rest and contain different information, so different fields need to be outputted with this. Also the second entry will be slightly different too.

Any help on how i could get this working would be great.


absolute_count is the right variable to use, as it should give you the count of the entry relative to the total number of entries available within the entries loop, ignoring pagination (whereas count resets for each pagination). So I'm surprised that the second example you provided didn't work.

The way I ordinarily handle such a condition is with the switchee add-on - it early parses the outer conditional (using switch case) and therein avoids parsing the inside of the condition/case that isn't satisfied.

So in this way, the setup would look like this:

 {exp:channel:entries channel="whatever" orderby="date" sort="desc" dynamic="no" disable="whatever|not|needed"}
     {exp:switchee parse="inward" var="{absolute_count}"}
       {case value="1|2"}
         first and second entries
       {case default="yes"}
         all other entries

Given that the larger ones would contain different info, it may be a little more than just applying a different class to absolute 1 and 2 and instead your different content markup would be contained between the two cases - the first matching 1 and 2 in your absolute count and the second matching all others that do not satisfy the first case.

Hope this helps.

  • Awesome, I will try that out and let you know. – zizther May 8 '13 at 11:44
  • I gave this a go too, but had no luck with it making the first 2 different. I am using EE 2.5.5, it is surprising me why none of this is working. – zizther May 8 '13 at 12:09
  • If you put absolute_count var in your loop, is it rendering with the numbers as expected? Anything different about your channel entries loop? Can you post the entries loop itself so we can see what else might be going on? – Jean St-Amand May 8 '13 at 15:04
  • So i have this working now. I changed var for variable in {exp:switchee}, don't know if that makes any difference. I am loading entries in with AJAX and i have worked out why i was getting confused with how EE works. – zizther May 8 '13 at 23:06
  • Excellent. Glad you have it working. I'm not sure if the fact you were loading entries via Ajax would have mattered or not. – Jean St-Amand May 9 '13 at 12:49

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.