Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have some landing pages that show the page title, feature image and excerpt of their children. The image is linked to the child page, but I need the page title linked to the same place - and I can't figure out how. Here is my existing code - it works perfectly, except the title is not linked. Any recommendations?

<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', 'page' ); ?>
<?php if ( is_page( 'foo' ) ) {
    $pageChildren = get_pages( array( 'child_of' => $post->ID, 'sort_column' => 'menu_order', 'hierarchical' => '0' ) );
    if ( $pageChildren ) {
    foreach ( $pageChildren as $pageChild ) {
    echo '
    <div class="foo-landing">
  <h2>' . $pageChild->post_title . get_the_post_thumbnail($pageChild->ID).'</h2>
  ';
  if ($pageChild->post_excerpt){
  echo '
  <p>'.$pageChild->post_excerpt.'</p>
</div>
';
    }
    }
    }
}
elseif  ( is_page( 'bar' ) ) {
    $pageChildren = get_pages( array( 'child_of' => $post->ID, 'sort_column' => 'menu_order', 'hierarchical' => '0' ) );
    if ( $pageChildren ) {
    foreach ( $pageChildren as $pageChild ) {
    echo '
    <div class="bar-landing">
  <h2>' . $pageChild->post_title .'</h2>
  ' . get_the_post_thumbnail($pageChild->ID);
  if ($pageChild->post_excerpt){
  echo '
  <p>'.$pageChild->post_excerpt.'</p>
  ';
  } echo '</div>
';
    }
    }
}
?>
<?php comments_template( '', true ); ?>
share|improve this question

1 Answer 1

up vote 0 down vote accepted

Using get_page_uri should do the trick:

<h2><a href="' . get_page_uri($pageChild) .'">' . $pageChild->post_title . get_the_post_thumbnail($pageChild->ID).'</a></h2>
share|improve this answer
    
that worked!! thank you so much. –  jamie Sep 25 '12 at 15:15

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.