Displaying categories for a single post

If you know the ID of a post you can bind the category data by using code similar to:

1
2
3
4
5
6
7
8
{post show="categories" post_id="{$post.ID}" assign_to="categories"}
 
<p class="category_links">
    {foreach $categories.data as $cat}
    <a href="{$cat.permalink}">{$cat.name}</a>
    {if $cat@last != 1}, {/if} {* add a comma is there is another category *}
    {/foreach}
</p>
{post show="categories" post_id="{$post.ID}" assign_to="categories"}

<p class="category_links">
    {foreach $categories.data as $cat}
    <a href="{$cat.permalink}">{$cat.name}</a>
    {if $cat@last != 1}, {/if} {* add a comma is there is another category *}
    {/foreach}
</p>

The result of this operation will bind a object with the following properties:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
array(6) {
  ["success"]=>
  bool(true)
  ["message"]=>
  string(7) "success"
  ["count"]=>
  int(1)
  ["action"]=>
  string(18) "appc_post_category"
  ["route"]=>
  string(18) "appc.post.category"
  ["data"]=>
  array(1) {
    [0]=>
    array(8) {
      ["id"]=>
      int(1)
      ["name"]=>
      string(13) "Miscellaneous"
      ["slug"]=>
      string(4) "misc"
      ["cat_permalink"]=>
      string(50) "http://appcropolis.net/category/misc/"
      ["permalink"]=>
      string(50) "http://appcropolis.net/category/misc/"
      ["description"]=>
      string(0) ""
      ["parent"]=>
      int(0)
      ["count"]=>
      int(7)
    }
  }
}
array(6) {
  ["success"]=>
  bool(true)
  ["message"]=>
  string(7) "success"
  ["count"]=>
  int(1)
  ["action"]=>
  string(18) "appc_post_category"
  ["route"]=>
  string(18) "appc.post.category"
  ["data"]=>
  array(1) {
    [0]=>
    array(8) {
      ["id"]=>
      int(1)
      ["name"]=>
      string(13) "Miscellaneous"
      ["slug"]=>
      string(4) "misc"
      ["cat_permalink"]=>
      string(50) "http://appcropolis.net/category/misc/"
      ["permalink"]=>
      string(50) "http://appcropolis.net/category/misc/"
      ["description"]=>
      string(0) ""
      ["parent"]=>
      int(0)
      ["count"]=>
      int(7)
    }
  }
}