Show Categories for a Post

This article will walk through some common scenarios and development approaches used to  display Post Categories on the website.

Show All Post Categories associated with a Post

This is useful when you want to show all Categories associated with a blog article (or perhaps categories associated with a "project", where a project is a Post). 

Step One: Get the Posts linked to the current page, and assign to the variable post:

<!-- This returns an array of all the Posts associated with the current page, so don't use this. --> <logic:variable as="posts" value="[? \Components\Website\Posts::getAllLinkingToPage(\Components\Website\Pages::currentPageId()) ?]" /> <!-- Use this instead, because you only want one Post. Gets the first Post in the array --> <logic:variable as="post" value="[? (\Components\Website\Posts::getAllLinkingToPage(\Components\Website\Pages::currentPageId()))[0] ?]" />
Step Two:
Use a data repeater get all the Post Categories associated with the Post:

<h4>Post Categories</h4> <ul> <data:repeater datasource="\Components\Website\Posts\Categories::getAllForPost($post['post_id'])" as="category"> <li><a href="[? $category ['page_id'] ?]">[? $category['post_category_title'] ?]</a></li> </data:repeater> </ul>
Step Three:
Need to filter out one of the Post Categories?

<h4>Post Categories</h4> <ul> <data:repeater datasource="\Components\Website\Posts\Categories::getAllForPost($post['post_id'])" as="category"> <logic:if test="$category['post_category_id'] != 1"> <!-- Do not display post category id 1 --> <li><a href="[? $category['page_id'] ?]">[? $category ['post_category_title'] ?]</a></li> </logic:if> </data:repeater> </ul>