WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to list the parent to a page in the sidebar. I can get the parent-page ID. I can get it to print with a print_r function, but no matter what I try I can't get get_permalink and get_the_title to display.

  <?php
    global $wp_query;

  if(!$wp_query->post->post_parent){  //no parent
      $children = wp_list_pages("title_li=&depth=1&child_of=".$wp_query->post->ID."&echo=0");   // will display the subpages of this top level page
  }else{    // diplays only the subpages of parent level

      if($wp_query->post->ancestors){
          $ancestors = end($wp_query->post->ancestors);
          $ancestorsID = get_post_ancestors($wp_query->post->ID); 
          $children = wp_list_pages("title_li=&child_of=".$ancestors."&echo=0");}
  }

  if ($children) { 
      echo '<ul>';

      if($wp_query->post->ancestors){
      echo '<li>'; print_r($ancestorsID[0]); get_permalink($ancestorsID[0]); get_the_title($ancestorsID[0]); echo '</li>'; }

      else {echo '<li><a href="';the_permalink(); echo '" title="Permalink to ';the_title(); echo '" rel="bookmark">'; the_title(); echo '</a></li>';}
      echo $children;
      echo '</ul>';
  } ?>
share|improve this question

use echo right before functions.

echo get_permalink($ancestorsID[0]); echo get_the_title($ancestorsID[0]);
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.