0

I have tried using the default wp next and previous link but when click it would go to another category post instead of the next post(product)

previous_post('« « %', 'previous', 'yes'); 
next_post('% » » ', 'next', 'yes'); 

when i try to put yes for the same category, the previous and next title disappears

previous_post('« « %', 'previous', 'yes','yes'); 
next_post('% » » ', 'next', 'yes','yes'); 

I also tried using

wpsc_first_products_link
wpsc_last_products_link

1 Answer 1

1

next_post function is deprecated.

You should try this instead: next_post_link and previous_post_link

The basic way to use it is like so: This will link to the next post or prev post.

<?php 
    next_post_link( '%link', '%title' );
    previous_post_link( '%link', '%title' ); 
?>

If you would like to link to the next post in the same category, add true after '%title'. This will work for the default posts and category.

<?php 
    next_post_link( '%link', '%title', true ); 
    previous_post_link( '%link', '%title', true ); 
?>

If you are using a CUSTOM POST TYPE with a CUSTOM TAXONOMY (like a product post), then you have to tell the function which taxonomy to look for the next post. eg.

<?php 
    next_post_link( '%link', '%title', true, '', 'custom_taxonomy' ); 
    previous_post_link( '%link', '%title', true, '', 'custom_taxonomy' ); 
?>

All the above examples have been tested and working.

8
  • i did try that but setting it to true doesnt make the next link visible at all
    – JPL
    May 8, 2015 at 6:18
  • if you add both next_post_link and previous_post_link. Do they both not show up? And also are there other posts in that category.
    – ngearing
    May 8, 2015 at 6:23
  • yes that is correct. and yes i have 10 post in one category.
    – JPL
    May 8, 2015 at 6:25
  • What is the category?
    – ngearing
    May 8, 2015 at 6:26
  • a product category in wp ecommerce
    – JPL
    May 8, 2015 at 7:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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