WordPress.org

Ready to get started?Download WordPress

Forums

I need to get the grandparents of a page for a breadcrumb trail navigation (1 post)

  1. semidivine
    Member
    Posted 6 years ago #

    ...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?

Topic Closed

This topic has been closed to new replies.

About this Topic