the_posts_pagination
works with the global $wp_query
, so your second method will not work.
query_posts
modifies the main query but the arguments passed will overwrite any existing values, so all values needed for pagination are lost when you set cat=5
. But you can preserve the existing values by modifying the global query string.
A more efficient way, however, would be to use the pre_get_posts action hook, e.g.:
function mysite_change_cat($query) {
//if it is a category archive page and main query
if ($query->is_category() && $query->is_main_query()) {
$query->set('cat', 5);
}
}
add_action('pre_get_posts', 'mysite_change_cat');
However if you are creating completely different pages for certain categories, then you could simply create template files for each of them named e.g. category-5.php.