2

I've found it perfectly possible to output a list of all of the categories for a channel, or a list of all of the categories that are not empty for a channel. But when I am iterating through the different posts of a channel, how can I output for each post only the categories that are checked for that specific channel entry?

I've read through the documentation pretty thoroughly, http://ellislab.com/expressionengine/user-guide/modules/channel/categories.html, and I can't seem to find a way to make it work.

I'm trying to spit this information out as JSON... to put it into context, below is what I have as a base. Ideally I would like to nest an array in my associative array that contains all of the categories for that channel entry.

<?php

  $entries = array();

  {exp:channel:entries channel="my_channel_entries" dynamic="yes"}
    $entries[] = array(
      'name' => '{entry_name}',
      'description' => '{description}'          
    );
  {/exp:channel:entries}

  header('Content-type: application/json');
  echo json_encode($entries, JSON_PRETTY_PRINT);
  exit;

?> 

Any help/creative problem solving that you all can offer will be greatly appreciated! Let me know if I can provide any more details to help you, help me.

2

I got bogged down with {exp:channel:categories} when I was getting started; in this context, you'll want to use the {categories} tag pair within {exp:channel:entries}.

| improve this answer | |
  • 2
    I'm surprised how many times I've seen this question -- I've just added a comment to the docs for Channel Categories in hopes of saving others the frustration down the road. – Derek Hogue Jan 3 '14 at 19:29
  • Yeah, it really, really threw me for a loop when I was getting started... I'm sure there are still some crazy templates out there floating around with really odd looking {exp:channel:category} loops in them. – Nick Benson Jan 3 '14 at 19:33
  • 1
    Hey thanks a lot @NickBenson ! That was exactly it... nothing too it :-) – rdgd Jan 3 '14 at 22:00

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.