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 ); ?>
Using get_page_uri should do the trick: