change recent posts based on category

You’re always displaying the posts from the category “category1” because that’s what you’ve written in your code here $rPosts->query('showposts=4&category_name=category1');

If you want to just go to the category archive pages you can do that by generating the links with get_term_link. This function goes at the position where you’re displaying the links & then this code is not needed. If not that please give us more details about where you’re displaying the links & how exactly you want it to work

As a side note “showposts” is deprecated, please use “posts_per_page” instead