Hi there – found a solution! I needed this to show a full category tree in the sidebar, but the image idea is great also ??
The code is this:
function get_topLevelParent ($postid) {
$pdata = get_post($postid);
$parent = $pdata->post_parent;
if ($parent != 0) {
$r = get_topLevelParent($parent);
} else {
$r = $postid;
}
return $r;
}
This function returns the top-level parent of any post. You can use it to build a sidebar with all children of a ‘master category’.
You can feed the current post ID to the function (it should work, I gave the parent ID anyway). Hope this solves your problem (even a little bit late ?? )