您可以尝试跳过CategoryThumbnailWalker
并使用list_cats
滤器
以下是一个未经测试的示例:
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 );
在哪里
/**
* 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;
}
输出(希望)如下:
<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>