GWcode Categories Examples
Here are some examples to demonstrate what you can do with GWcode Categories:
- Example 1 - Showing categories for an entry
- Example 2 - Showing last child categories only
- Example 3 - Showing categories of any (fixed, minimum or maximum) depth
- Example 4 - Showing the entry count for categories
- Example 5 - Category based breadcrumbs
- Example 6 - Automatic nested numbering
- Example 7 - Counting categories
- Example 8 - Conditionals
- Example 9 - Showing child categories or parent categories
- Example 10 - Sorting categories
- Example 11 - Creating a menu with specific code
Example 2 - Showing last child categories only
The last_only parameter can be used to display last child categories only.
My "example" channel has been assigned a category group with the following categories:
- cat1
- cat1_1
- cat1_1_1
- cat1_1_2
- cat1_1_2_1
- cat1_2
- cat1_1
- cat2
- cat2_1
To get the last child categories only (highlighted in blue) for this channel, the following code can be used:
{exp:gwcode_categories channel="example" last_only="yes"}
{cat_name}
{/exp:gwcode_categories}
..which will return a simple nested list of last child categories:
- cat1_1_1
- cat1_1_2_1
- cat1_2
- cat2_1
Of course, you can also show the categories in a linear form by using the style="linear" parameter.
If you'd like to show last child categories for an entry, use the entry_id instead of the channel parameter:
{exp:gwcode_categories entry_id="20" last_only="yes"}
{cat_name}
{/exp:gwcode_categories}
Or last child categories for certain category groups:
{exp:gwcode_categories group_id="1|2|3" last_only="yes"}
{cat_name}
{/exp:gwcode_categories}
You can also use a category as a starting point. For example, if you want to show last child categories with cat1 in the example above as the starting point, it will return cat1_1_1, cat1_1_2_1 and cat1_2:
{exp:gwcode_categories cat_id="13" last_only="yes"}
{cat_name}
{/exp:gwcode_categories}
