如果你的主题很好的话get_the_post_thumbnail
检索特征图像。此函数有一个过滤器,可用于检测是否存在特征图像,如果没有,则将其替换。像这样:
add_filter (\'post_thumbnail_html\',\'wpse251260_thumbnail_html\', 10, 5)
wpse251260_thumbnail_html ($html, $post_id, $post_thumbnail_id, $size, $attr) {
if ( \'\' === $html ) {
.. do stuff depending on category you retrieve with $post_id;
}
return $html
}