Calling function in loop causes repeat data
first of all, you could delete the return $ranking += 1; and replace by $ranking += 1;. We don’t know what happend in the template-parts/content, but don’t forget to add a little <?php wp_reset_postdata(); ?> just after your endwhile;.