Question
I want to display the lowest level category for an entry, the opposite of the parent paramter
Answer
(There may be a better way…)
{exp:weblog:entries limit="1"}
{categories}
<?php
$lastcatname="{category_name}";
?>
{/categories}
<h1>Category: <?php echo $lastcatname; ?></h1>
...
For this to work, Allow PHP must be turned ON in the Template Preferences and set to OUTPUT.
Alternative for hiding main parents only
The main-categories have no parents, only children have.
If you want to hide the parents, check that there is no parent_id
cars
ford
audi
volvo
airplanes
boeing
airbus
{exp:weblog:entries limit="1"}
{title}<br>
{categories}
{if parent_id !="0"}{category_name}{/if}
{/categories}
{/exp:weblog:entries}
...
or
{categories}
<span class="cat{parent_id}">{category_name}</span>
{/categories}
...
caveat: you can’t use backspace=“1” so you could use a span to style, space or hide things with CSS.
in the 2nd example here the code would result in a span with class=“cat0” for top-parents.
Add-ons
There are following plugins which could be used to output info about parent and child categories:
-
Category:Tricks Category:Categories
