我有一些登录页,显示页面标题、功能图片和他们孩子的摘录。图像链接到子页面,但我需要将页面标题链接到同一个位置,我不知道如何链接。这是我现有的代码-它工作得很好,只是标题没有链接。有什么建议吗?
<?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 ); ?>
最合适的回答,由SO网友:retsoced 整理而成
使用get\\u page\\u uri应该可以做到:
<h2><a href="\' . get_page_uri($pageChild) .\'">\' . $pageChild->post_title . get_the_post_thumbnail($pageChild->ID).\'</a></h2>