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;.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)