我制作了一个页面模板,使用以下代码显示链接的子页面:
<?php
$mypages = get_pages( array( \'child_of\' => $post->ID, \'sort_column\' => \'menu_order\', \'sort_or
foreach( $mypages as $page ) {
$content = $page->post_content;
if ( ! $content ) // Check for empty page
continue;
$content = apply_filters( \'the_content\', $content );
?>
<h2><a href="<?php echo get_page_link( $page->ID ); ?>"><?php echo $page->post_title; ?></a><
<div class="entry"><?php echo $content; ?></div>
<?php
}
?>
我拿到密码了
from here 并将其更改为按页面顺序排列子页面。
它可以工作,但它会显示整个页面的内容。我只想让它显示页面摘录和特色图片。
(我在编辑器中通过添加add_post_type_support( \'page\', \'excerpt\' );
至功能。php)
如何修改此页面模板以显示子页面摘录?
最合适的回答,由SO网友:Mridul Aggarwal 整理而成
稍微修改这些行
$content = $page->post_content;
if ( ! $content ) // Check for empty page
continue;
$content = apply_filters( \'the_content\', $content );
至
$content = $page->post_excerpt;
if ( ! $content ) // Check for empty excerpt content & fallback to full content
$content = $page->post_content;
if ( ! $content ) // Check for empty page
continue;
$content = apply_filters( \'the_excerpt\', $content );
更新:用于添加特色图像使用
<div class="image"><?php echo get_the_post_thumbnail($page->ID);?></div>
SO网友:kaiser
这个示例展示了如何利用插件将其操作挂钩到过滤器或挂钩中。它还允许对子帖子使用密码保护,包括默认的核心翻译字符串。
$wpse69264_child_pages = get_pages( array(
\'child_of\' => in_the_loop ? get_the_ID() : $post->ID // Are we in the loop?
,\'sort_column\' => \'menu_order\'
,\'sort_order\' => DESC
) );
foreach ( $wpse69264_child_pages as $child )
{
// Default filters: Excerpt length - Also takes languages in account where 1 char = 1 word (like Chinese)
$output = $child->post_excerpt ? $child->post_excerpt : apply_filters( \'excerpt_length\', $child->post_content );
if ( post_password_required( $child ) )
{
// Default translation
_e( \'There is no excerpt because this is a protected post.\' );
continue;
}
// Just in case
$output = force_balance_tags( $output );
// Default filters:
$output = apply_filters( \'get_the_excerpt\', $output );
echo apply_filters( \'the_excerpt\', $output );
}
unset( $wpse69264_child_pages, $child );