WordPress.org

Support

Support » How-To and Troubleshooting » I need to get the grandparents of a page for a breadcrumb trail navigation

I need to get the grandparents of a page for a breadcrumb trail navigation

  • …and I don’t want to use a plugin… none of the plugins I tried worked with a language switching plugin I use, so I have to create this myself.

    I have the pages grabbing the parent and creating a link with this code:

    <?php
    	global $wp_query;
    	if (empty($wp_query->post->post_parent) ) {
    		$parent = $wp_query->post->ID;
    		echo '';
    	} else {
    		$parent = $wp_query->post->post_parent;
    		echo '<a href="'.get_permalink($parent).'">'.get_the_title($parent).'</a> &raquo;';
    	}
    ?>

    But this only gets the parent. I would love to know how to access the grandparents or great grandparents of the page and put them in the right order. Does anybody know how to do this?

  • The topic ‘I need to get the grandparents of a page for a breadcrumb trail navigation’ is closed to new replies.