Expert Group of programming
Loading...

Display posts from the same category using next/previous post link

Posted by : Heycode Tech | Posted in : pagination, wordpress | Sep 12,2015 | 5 comments

WordPress have the function for creating an pagination. By default wordpress, use the pagination of the all category but if any special case you need the pagination on the same category only, then here is the way.

Single.php file :Pagination for same category

<strong>WordPress pagination in same category :</strong>
<?php next_post_link( '%link', 'Next post in category', TRUE ); ?>
<?php previous_post_link('%link', 'Previous in category', TRUE); ?> 

Use this code in single.php and custom template file only.

Single.php file :Pagination for all category

<strong>WordPress pagination in same category :</strong>
<?php next_post_link( '%link', 'Next post in category', FALSE); ?>
<?php previous_post_link('%link', 'Previous in category', FALSE); ?> 

Use this code in single.php and custom template file only.

Use other default template file.
Like : category.php , archive.php,  tag.php, taxonomy.php,  author.php,  date.php,  search.php and any custom template file.

<?php previous_posts_link( '« Newer Entries' ); ?>
<?php next_posts_link( 'Older Entries »', 0 ); ?>

Check if next link exists

<?php if( get_next_posts_link() ) :
next_posts_link( 'Older Entries »', 0 );
endif; ?>

 
Check if previous link exists

<?php if( get_previous_posts_link() ) :
previous_posts_link( '« Newer Entries' );
endif; ?>

 
Posts Per Page settings

For posts per page settings, you need to follow the path :

Settings – > Path
Reading Settings ‹ HeyCode Tech — WordPress 2015-09-12 02-23-28

Let me know if needs anything else .

Tags:

Author information - Heycode Tech

Every world can ask question and my website registered user give the suggestion.

See all posts by Author

Connect to author
5 Comments
  1. Can you inform me what system are you making use
    of on this web site?

    • Replied to Laurene
      Heycode Tech

      Hi Laurene,
      I am a developer of : WordPress + CodeIgniter : and here is my website and I want to do the : Freelance work: .


      Heycodetech

  2. Hi there! Such a great post, thank you!

  3. Could you inform me what theme are you using on your internet site?

    It looks wonderful.

  4. Do you have any type of suggestions for creating write-ups?

    That’s where I constantly struggle as well as I just wind up
    staring vacant screen for long time.

Leave a Reply

Your email address will not be published. Required fields are marked *

About us

Heycodetech is a platform where you can ask any questions related to the programming like PHP,jQuery, MYSQL,HTML , CSS and more Here is the Expert group of programming.