然而,你的想法是对的;
不要使用query_posts
, use get_posts
instead使用wp_list_pages
过滤器只会使用模板标记将列表添加到末尾,如the_permalink()
将回显输出,因此您不能在中使用它string concatenation您需要使用custom walker (用于生成层次结构内容的类家族),这将允许您在帖子页面之后插入列表:
/**
* Add 10 most recent posts as a child list of the posts page.
*
* @link https://wordpress.stackexchange.com/q/141929/1685
*/
class WPSE_141929_Walker extends Walker_Page {
function start_el( &$output, $page, $depth = 0, $args = array(), $current_page = 0 ) {
parent::start_el( $output, $page, $depth, $args, $current_page );
if ( $page->ID == get_option( \'page_for_posts\' ) ) {
$posts = get_posts(
array(
\'posts_per_page\' => 10,
)
);
if ( $posts ) {
$output .= \'<ul class="children">\';
foreach ( $posts as $post ) {
$output .= \'<li><a href="\' . get_permalink( $post->ID ) . \'">\' .get_the_title( $post->ID ) . \'</a></li>\';
}
$output .= \'</ul>\';
}
}
}
}
使用中:
wp_list_pages(
array(
\'walker\' => new WPSE_141929_Walker,
)
);