0

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>';
  } ?>
2

use echo right before functions.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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