• Resolved carbon 972

    (@fscottneeson)


    Hi there, I wonder if anybody could help me with this.

    My main navigation menu contains links to the three categories I have on my site (ex. Photos, Diary, News). So when you click on that link it displays all the posts within that category.

    However, the pagination links at the bottom of each single-post page link to the next/previous post on the site regardless of what it’s category is. So, for example, any given single-post in the “Photos” category may have a “Previous Post” pagination link at the bottom, which does indeed link to the previous post, but which may be a post in an entirely different category, for example “News”.

    Is there someway I can get it so a single-post in a given category will only link to the previous/next post within that category? So readers can scroll through all the posts in that category one-by-one?

    If anyone has a solution I would greatly appreciate it, thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Theme Author Anders Norén

    (@anlino)

    Hi @fscottneeson,

    Not without a bit of custom development, unfortunately.

    There is a parameter called in_same_term in the arguments for the the_post_navigation function, which is used to display the single post links. That means that you could copy over the content.php file to a Chaplin child theme, and in the child theme file, replace this:

    // Single post navigation
    		if ( is_single() ) {
    			the_post_navigation( array(
    				'prev_text' => '<span class="arrow" aria-hidden="true">&larr;</span><span class="screen-reader-text">' . __( 'Previous post:', 'chaplin' ) . '</span><span class="post-title">%title</span>',
    				'next_text' => '<span class="arrow" aria-hidden="true">&rarr;</span><span class="screen-reader-text">' . __( 'Next post:', 'chaplin' ) . '</span><span class="post-title">%title</span>',
    			) );
    		}

    With this:

    // Single post navigation
    		if ( is_single() ) {
    			the_post_navigation( array(
    				'prev_text' 	=> '<span class="arrow" aria-hidden="true">&larr;</span><span class="screen-reader-text">' . __( 'Previous post:', 'chaplin' ) . '</span><span class="post-title">%title</span>',
    				'next_text' 	=> '<span class="arrow" aria-hidden="true">&rarr;</span><span class="screen-reader-text">' . __( 'Next post:', 'chaplin' ) . '</span><span class="post-title">%title</span>',
    				'in_same_term' 	=> true,
    			) );
    		}

    … after which the links to point to the previous/next post in the same category.

    — Anders

    Thread Starter carbon 972

    (@fscottneeson)

    That worked great. Thanks so much, love all your themes and sense of simple design by the way!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Is it possible to have pagination within a category on single posts?’ is closed to new replies.