WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Display a link back to the Parent Page underneath (3 posts)

  1. wpNewbie80
    Member
    Posted 5 years ago #

    hello, I'm sorry to keep posting but I am trying to display my Page's content and then underneath, show a link back to the Page's parent page (if it has one).

    I have tried the following but I keep getting a link to the current Page.the title is correct though..

    <div class="entry">
    
          <?php the_content();?>
    
          <?php
            if (!empty($post->post_parent)) {
               $parentTitle = get_the_title($post->post_parent);?>
    
                <a href="<?php get_permalink($post->post_parent); ?>" title="<?php echo $parentTitle; ?>">Back to <?php echo $parentTitle; ?></a>
    
          <?php
             }
    	 edit_post_link('Edit','','');?>
    
      </div>

    As you can pass an ID to get_permalink etc I thought I would be able to do $post->post_parent. Am I far wrong and is it ok to be doing this within the loop still??

    Thank you for your time

    JJ

  2. wpNewbie80
    Member
    Posted 5 years ago #

    so sorry, I forgot to echo get_permalink

  3. csleh
    Member
    Posted 5 years ago #

    which means that this works:

    <?php
       if (!empty($post->post_parent)) {
        $parentTitle = get_the_title($post->post_parent);?>
      <a href="<?php echo get_permalink($post->post_parent); ?>" title="<?php echo $parentTitle; ?>">Back to <?php echo $parentTitle; ?></a>
      <?php } ?>

    I'm using 2.7.1

Topic Closed

This topic has been closed to new replies.

About this Topic