WordPress.org

Forums

Print Parent page title (8 posts)

  1. barretoivoski
    Member
    Posted 7 years ago #

    Hi,

    How can I print Parent page title in a child or own parent page? is that possible?

  2. Chris Harrison
    Member
    Posted 7 years ago #

    I've been wondering this myself. I just found this article and it works like a charm!

    http://expatrick.com/2007/04/14/wordpress-name-of-parent-page/

    <?php if (is_page()) {
      if (!empty($post->post_parent)) {
       $extradata = $wpdb->get_row("select post_title from wp_posts where ID = " . $post->post_parent);
       echo $extradata->post_title;
      } else {
       echo $post->post_title;
      }
     } else {
      echo "your text here";
    }
    ?>
  3. hvaninah
    Member
    Posted 7 years ago #

    Hi!
    I've found that :
    <?php
    $parent_title = get_the_title($post->post_parent);
    echo $parent_title;
    ?>
    Good luck!

  4. Mattz
    Member
    Posted 7 years ago #

    I was not able to print the name of a parentpage using:

    $parent_title = get_the_title($post->post_parent);

    IS this doable using a small line of code ?

  5. willroy
    Member
    Posted 6 years ago #

    $parent_title = get_the_title($post->post_parent);

    should work.

  6. kcal
    Member
    Posted 6 years ago #

    I used code suggested by hvaninah in a 2.7 version and it worked like magic! Thanks

  7. bcnewmedia
    Member
    Posted 6 years ago #

    or how about just <?php echo get_the_title($post->post_parent);?>

  8. Joe Rhoney
    Member
    Posted 6 years ago #

    Awesome! Thanks bcnewmedia! That did exactly what I needed. :j

Topic Closed

This topic has been closed to new replies.

About this Topic