0

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

2 Answers 2

2

try adding :

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

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

4
  • 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
    Commented Aug 9, 2011 at 13:31
  • why? whats your permalink structure, also did you recently change it?
    – Bainternet
    Commented Aug 9, 2011 at 13:39
  • Thats my structure (didn't configured clear links yet): /index.php/%category%/%postname%/ and yeah, I did changed it recently.
    – smogg
    Commented Aug 9, 2011 at 13:43
  • i wonder how many times this question is asked. We should have a commonly asked question page.
    – Sisir
    Commented Nov 14, 2011 at 17:28
0

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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