Need to make a mini-menu.

There is a code that displays, the name of the parent of this page must be done so that this name is displayed by a link, that is, in which case the user could click, and go back to the branch.

<?php if ( 0 == $post->post_parent ) { the_title(); } else { $parents = get_post_ancestors( $post->ID ); echo apply_filters( "the_title", get_the_title( end ( $parents ) ) ); } ?> 

It is necessary that the result be something like this:

 Имя родителя > Имя текущей страницы 

It was for categories that I found snippet in wordpress site, but for pages like this, it turned out to be not so easy. The meaning of the idea is that while navigating, the user could simply click on the “branches” that he follows. And do not refer to the example of the menu, which is from the side of the site bar and twist scrolled.

    2 answers 2

    what you want to do can be "Bread Crumbs", that is, the path from the main page of the site to the page you are on or sub-page. Link to the wp-kama article

    • Thank you, I just didn’t know what it was called, but I found similar functions on two sites and combined them to the minimum. For I am not in all sections, the results, they are needed. - webstackoverload
    • I was glad to help you - Yuriy Chaban
    • @webstackoverload if the answer helped solve the problem - mark it as resolved. And for breadcrumbs there are ready-made plugins. - SeVlad

    To get the link, it is enough to use get_permalink for post_parent - in this case the code will be like this:

     <?php if (0 == $post->post_parent) { the_title(); } else { echo '<a href="'.get_permalink($post->post_parent).'">'.get_the_title($post->post_parent).'</a>'; echo ' > '; the_title(); } ?>