1

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 ); ?>

1 Answer 1

1

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>
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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