Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I know there have been many question like this and I've read them, but I still cant get it working... I have this query:

query_posts(array('cat'=>3,'posts_per_page'=>5));

And I simply display the content below in while (have_posts()) : the_post(); loop How can I add pagination to this? I'm trying with adding posts_nav_link(); ( I don't know is it the right function to call what I want) and links displayed take me to http://mysite.com/page/2. Since its my index page its ok to not add category name in link (its news page) but after clicking on the link, when I'm on the page/2/ news simply doesn't change. I still see the first page of my news without change... I think I need to add attribute of 'paged' to my query, but how and where? I've tried 'paged'=>'paged' in array but still nothing

share|improve this question
add comment

2 Answers

try adding :

$page = (get_query_var('paged')) ? get_query_var('paged') : 1;

and then in your args array add 'paged'=> $page

share|improve this answer
    
Yeah, that works but now I have another problem. While its my index page "next" link takes me to mywebsite.com/page/2 and it doesnt work cause it should be mysite.com/news/page/2 How can I add "news/" to adress? –  smogg Aug 9 '11 at 13:31
    
why? whats your permalink structure, also did you recently change it? –  Bainternet Aug 9 '11 at 13:39
    
Thats my structure (didn't configured clear links yet): /index.php/%category%/%postname%/ and yeah, I did changed it recently. –  smogg Aug 9 '11 at 13:43
    
i wonder how many times this question is asked. We should have a commonly asked question page. –  Sisir Nov 14 '11 at 17:28
add comment

There is a known issue in WP that causes pagination errors if you have duplicate slugs/names between a custom post type and a Page. If you have a custom post type called news and a page that also has a slug of news, your pagination will not work with query_posts.

To fix this, change the slug of your News page to something else and reset your permalinks. Should be all set.

(sorry this is a separate answer- I just joined and dont see the option to 'reply' to a previous Answer)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.