Regarding the above, this part is a little pointless.
<?php $posts=query_posts($query_string . '&cat=8'); ?>
In might aswell be..
<?php query_posts($query_string . '&cat=8'); ?>
As there’s absolutely no benefit or reasoning to adding the query_posts line onto a variable as you have done…
The other steps I see in many sites are waste of time and so complicated, and after doing everything the pagination will not work as to be.
Pagination will work if you setup the postdata and/or add the paging variable into the query_posts parameters (depending on the type of query you use, query_posts, foreach loop, etc)…. Complicated really is subjective, you either understand the instructions given or you don’t.
These “How do i limit to one category” questions have been asked numerous times on the forum, so amongst the pages of instructions and threads on this forum i do find it a little hard to understand how even a non-coder struggles.
1. Determine which file handles the page you want to effect posts on.
https://codex.www.ads-software.com/Template_Hierarchy
https://codex.www.ads-software.com/images/1/18/Template_Hierarchy.png – Nice easy way to determine which file handles what.
2. Open said file, and add a conditional
3. Example
If index.php handles various cases for you site (let’s say it handles the home/front page, but also handles other areas to)..
You’d find the loop first…
https://codex.www.ads-software.com/The_Loop
If you don’t have a query_posts line, you can it in, else add to it as Michael showed by preserving the existing query string.
https://codex.www.ads-software.com/Template_Tags/query_posts
Then add a conditional before or around it..
https://codex.www.ads-software.com/Conditional_Tags
..here’s some examples (much like Michaels initial one).
if(is_home()) {
query_posts( $query_string . '&cat=1' );
}
if(is_front_page()) {
query_posts( $query_string . '&cat=1' );
}
If you have a query posts line already in your file, then you just add an else condition to the above examples..
else {
// If you had a query posts call
// query_posts( $query_string );
// or
// query_posts( WHATEVER WAS IN YOUR ORIGINAL CALL );
}
I could go much more in-depth, but i feel i’d only be repeating what’s already been discussed numerous times in various other threads.