You’ve got the right idea, however;
- Don’t use
query_posts
, useget_posts
instead - Using the
wp_list_pages
filter will just add the list at the end - Using template tags like
the_permalink()
will echo the output, so you can’t use it in string concatenation
You’ll need to use a custom walker (the family of classes for generating hierarchical content), which will allow you to inject your list right after the posts page:
/**
* 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>';
}
}
}
}
And in use:
wp_list_pages(
array(
'walker' => new WPSE_141929_Walker,
)
);