你基本上是在检查( $query->current_post + 1 ) % 5 == 0. 对于最后一篇文章,其中$query->current_post 等于9, 这也会返回true,如下所示10 % 5 等于0. 因此div 和aul 输出。
您可以通过检查是否还有任何帖子要显示(使用$query->post_count, 显示的帖子数):
if ( $query_count % 5 == 0 && $query_count < $query->post_count )