Support » Themes and Templates » display page parent on page with title

  • Resolved noname1


    I have no trouble displaying the_title on a page. But can’t find the tag from the codex to show the page parent. Namely, so I can create a crumb-trail, but also as several subpages from different parents have the same title.

Viewing 13 replies - 1 through 13 (of 13 total)
  • will this work?
    is there an easier way?

    $parent = wp_list_pages("title_li=&parent_of=".$post->post_child."&echo=0"); else
    $parent = wp_list_pages("title_li=&parent_of=".$post->ID."&echo=0");
    if ($parent) { ?>

      <?php echo $parent; ?>

    <?php } ?>

    $post->post_parent will give you the ID of the parent page 🙂

    if you want to keep checking further back, you can pull the parent page and find out what it’s parent is….

    $parent = get_page($post->post_parent);
    $grandparent = $parent->post_parent;

    just thought – is there simply a crumb tag?

    there isn’t but there are a couple of breadcrumb plugins.

    you’re welcome by the way.

    ivovic – would the code you posted a few weeks ago be adaptable?

    <div id="breadcrumbs">
    <a href="<?php echo get_bloginfo('url'); ?>" title="">Home</a>
      $breadcrumbs = explode('|',get_category_parents($cat,true,'|'));
      if ($breadcrumbs) foreach ($breadcrumbs as $crumb) echo ' / '.$crumb;
    <h1><?php single_cat_title(); ?></h1>

    that’s for category pages… you would use that only on category archive templates.

    this is what I use for breadcrumbs on my page.php and other page templates.

    <div id="breadcrumbs">
      <a href="<?php echo get_bloginfo('url'); ?>" title="">Home</a>
        $parent_id  = $post->post_parent;
        $breadcrumbs = array();
        while ($parent_id) {
          $page = get_page($parent_id);
          $breadcrumbs[] = '<a href="'.get_permalink($page->ID).'" title="">'.get_the_title($page->ID).'</a>';
          $parent_id  = $page->post_parent;
        $breadcrumbs = array_reverse($breadcrumbs);
        foreach ($breadcrumbs as $crumb) echo ' / '.$crumb;
    <h1><?php the_title(); ?></h1>

    since I’m posting all my code here, and you’re cutting and pasting, don’t you think it would just be easier to use a breadcrumb plugin? 😉

    thanks – i’ll try this. i wouldn’t learn anything using a plugin.

    thanks Ivovic – i tried that code – will have to change it a bit – but that’s the tag i was looking for. shame the codex is so difficult to navigate.

    yeah, there’s no way I could have found that stuff in there 😛

    Great to have found this today! I’m super novice at PHP, but got this working, only I was wondering how it can be changed to display top level parent pages (so only one page parent title would appear – even if you are at sub sub levels of pages)


    Awesome, thank you ivovic, can’t believe this isn’t posted in a more public place. A may soon combine your hierarchicial script here with ForTheLose’s breadcrumbs

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘display page parent on page with title’ is closed to new replies.