You can try to skip the CategoryThumbnailWalker
and use instead the list_cats
filter.
Here’s an untested example:
add_filter( 'list_cats', 'wpse_149898_list_cats', 99, 2 );
wp_list_categories(array(
"child_of" => get_queried_object_id(),
"depth" => 1,
"hide_empty" => false,
"hierarchical" => 1,
"orderby" => "name",
"pad_counts" => 0,
"post_type" => "projects",
"show_count" => 0,
"show_option_none" => "",
"taxonomy" => "project-category",
"title_li" => "",
));
remove_filter( 'list_cats', 'wpse_149898_list_cats', 99, 2 );
where
/**
* Prepend the featured image, from the most recent project
* in a custom taxonomy, to the term name.
*
* @param string $cat_name
* @param object $category
* @return string
*/
function wpse_149898_list_cats( $cat_name, $category )
{
$posts = get_posts( array(
'post_type' => 'projects',
'posts_per_page' => 1,
'meta_key' =>'_thumbnail_id',
'project-category' => $category->slug,
) );
$img = sprintf( "<img alt=\"No image available\" src=\"%s/img/no-image.jpg\" />",
get_template_directory_uri()
);
if ( $posts ):
foreach ( $posts as $post )
{
if ( has_post_thumbnail( $post->ID ) )
$img = get_the_post_thumbnail( $post->ID, 'gallery-small' );
}
endif;
return $img . $cat_name;
}
The output should (hopefully) be like this:
<li class="cat-item cat-item-13">
<a href="http://christopherconsultants.myweblinx.net/project-category/education/" title="View all posts filed under Education">
<img alt="No image available" src="http://christopherconsultants.myweblinx.net/wp-content/themes/christopher-consultants/img/no-image.jpg">
Education
</a>
</li>