Use wp_list_pages custom walker to show only post thumbnails
In this example the project required the featured image thumbnail to display in the menu for every page, so rather than displaying a list of links to pages, there is a menu of images. An advanced function which extends the walker class.
/** * Snippet Name: Use wp_list_pages custom walker to show only post thumbnails * Snippet URL: https://wpcustoms.net/snippets/custom-walker-post-thumbnails/ */ // create our custom thumbnail walker class Thumbnail_walker extends Walker_page { function start_el(&$output, $page, $depth, $args, $current_page) { if ( $depth ) $indent = str_repeat("\t", $depth); else $indent = ''; extract($args, EXTR_SKIP); $css_class = array('page_item', 'page-item-'.$page->ID); if ( !empty($current_page) ) { $_current_page = get_page( $current_page ); _get_post_ancestors($_current_page); if ( isset($_current_page->ancestors) && in_array($page->ID, (array) $_current_page->ancestors) ) $css_class[] = 'current_page_ancestor'; if ( $page->ID == $current_page ) $css_class[] = 'current_page_item'; elseif ( $_current_page && $page->ID == $_current_page->post_parent ) $css_class[] = 'current_page_parent'; } elseif ( $page->ID == get_option('page_for_posts') ) { $css_class[] = 'current_page_parent'; } $css_class = implode( ' ', apply_filters( 'page_css_class', $css_class, $page, $depth, $args, $current_page ) ); // here comes the fun part where we insert our featured post image sized at 80x80px $output .= $indent . '
- ';
global $wp_query;
if ( is_page() || is_attachment() || $wp_query->is_posts_page )
$current_page = $wp_query->get_queried_object_id();
$output .= walk_page_tree($pages, $r['depth'], $current_page, $r);
if ( $r['title_li'] )
$output .= '