Support » Fixing WordPress » Display a link back to the Parent Page underneath

  • Resolved wpNewbie80

    (@wpnewbie80)


    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

Viewing 2 replies - 1 through 2 (of 2 total)
  • so sorry, I forgot to echo get_permalink

    csleh

    (@csleh)

    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

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Display a link back to the Parent Page underneath’ is closed to new replies.