1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
$parentsDirs = "";
if( !$leavename ){
$postId = $post->ID;
if ( !in_array($post_type, array('topic', 'forum', 'reply') ) ) {
while ($parent = get_post($postId)->post_parent) {
$parentsDirs = get_post($parent)->post_name."/".$parentsDirs;
$postId = $parent;
}
}
}