WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] display page parent on page with title (14 posts)

  1. noname1
    Member
    Posted 6 years ago #

    hello
    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.
    m

  2. noname1
    Member
    Posted 6 years ago #

    will this work?
    is there an easier way?

    <?php
    if($post->post_child)
    $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 } ?>

  3. Ivovic
    Member
    Posted 6 years ago #

    $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;

  4. noname1
    Member
    Posted 6 years ago #

    just thought - is there simply a crumb tag?

  5. Ivovic
    Member
    Posted 6 years ago #

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

    you're welcome by the way.

  6. noname1
    Member
    Posted 6 years ago #

    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>
    <?php
      $breadcrumbs = explode('|',get_category_parents($cat,true,'|'));
      array_pop($breadcrumbs);
      array_pop($breadcrumbs);
      if ($breadcrumbs) foreach ($breadcrumbs as $crumb) echo ' / '.$crumb;
    ?>
    </div>
    <h1><?php single_cat_title(); ?></h1>
  7. Ivovic
    Member
    Posted 6 years ago #

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

  8. Ivovic
    Member
    Posted 6 years ago #

    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>
      <?php
        $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;
      ?>
    </div>
    <h1><?php the_title(); ?></h1>
  9. Ivovic
    Member
    Posted 6 years ago #

    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? ;)

  10. noname1
    Member
    Posted 6 years ago #

    thanks - i'll try this. i wouldn't learn anything using a plugin.

  11. noname1
    Member
    Posted 6 years ago #

    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.

  12. Ivovic
    Member
    Posted 6 years ago #

    yeah, there's no way I could have found that stuff in there :P

  13. patricia1706
    Member
    Posted 5 years ago #

    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)

    Thanks!

  14. tison
    Member
    Posted 5 years ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Topic