I am trying to get the max results for the categories inside this channel entry. If the current category is the last one in the loop I don't want to add a , after the output.

   {exp:channel:entries channel="ch_efn_gallery" entry_id="295"}
           {if categories:count!=categories:total_results},{/if}

categories:count gives me the correct number. But categories:total_results doesn't work. And i din't find out how to get the max value for categories. Actually this template has much more output but i shortened it to the core of my problem.

3 Answers 3


I solved my problem by using php. First i go through all of the categorys and count them. after that i check it with another variable where i count the current Category.

{exp:channel:entries channel="ch_efn_magazin" entry_id="304"}
     "ID": "{entry_id}",
     "Category": [{
        <?php $maxCat = 0; $currentCat = 0; ?>
           <?php $maxCat++; ?>

          "{category_id}":"{category_name}"<?php $currentCat++; if($maxCat != $currentCat) echo(','); ?>

The whole reason I am doing this, is to create a JSON file. I know that there is this Json Plugin by Rob Sanchez but with this plugin I wans't able to loop through my Channel_Images. That's why I decided to do it like this.


You could try and simply use the backspace tag

Assuming it's that straight forward. I've never really liked the EE categories tag, I lean towards GW Categories. You can then disable categories in your main loop to save some overhead.

  • {categories style="linear" backspace="1"} does not work. and i am using 2.9 that's why at the moment ints not possible for me to use GW Categories...
    – MrTouch
    Mar 3, 2016 at 10:08
  • What, GW doesn't work on 2.9? Mar 3, 2016 at 10:38
  • i'm sorry, i red it wrong. it's possible to use it. but i was able to fix my problem with php.
    – MrTouch
    Mar 3, 2016 at 12:58
  • For the record, php in this context is a bad idea. Pls post your solution as an answer Mar 3, 2016 at 13:38
  • I know that my solution is kinda ugly, because I am using php. But I didn't saw another way to do it. I posted my solution as an answer.
    – MrTouch
    Mar 3, 2016 at 14:39

GW Categories is free, but for EE1 and EE2 only - do something like:

{exp:gwcode:categories entry_id=“295" style=“linear” backspace=“1"}

If you want to work in EE3 (or plan to) you could use Category Construct as a direct replacement - though currently the ‘backspace’ feature in Category Construct is broken.

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.