• currently writing some code to display posts from a certain category but when I add the code
    <?php next_post_link('%link', 'Next', true); ?>

    The next post link doesn’t display, but it does display if I set the setting for “in_same_cat” to “false” but it shows the link to a post in a different category. I have 4 post in the category I am viewing so a next post does exist, the same problem happens with “previous_post_link”

    I call my code within the loop in single.php this is my code below

    <?php while ( have_posts() ) : the_post(); ?>
    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    	<header class="entry-header">
    		<h1 class="entry-title"><?php the_title(); ?></h1>
    
    		<?php if ( 'post' == get_post_type() ) : ?>
    		<div class="entry-meta">
    			<?php twentyeleven_posted_on(); ?>
    		</div><!-- .entry-meta -->
    		<?php endif; ?>
    	</header><!-- .entry-header -->
    
    	<div class="entry-content">
        	<div style="float:left; margin-right:6px; margin-bottom:2px; margin-top:4px;">
    		<?php the_post_thumbnail(array(300,999) ); ?>
    		</div>
    		<?php the_content(); ?>
    	</div><!-- .entry-content -->
    </article><!-- #post-->
    
    <?php next_post_link('%link', 'Next', true); ?>
    <?php previous_post_link('%link', 'Previous', true); ?>

    Any ideas community?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The problem could be that the posts are assigned more than one category. In that case, the ‘same category’ chosen by previous/next_post_link() might not be the same main one from the original post, but one of the others.

    Here is an article that discusses the problem:

    https://wordpress.mcdspot.com/2010/06/02/stay-in-category/

    Thread Starter tinsterman

    (@tinsterman)

    The posts are in one category called “blog”, but they are first called by a file called category-blog.php

    I will try the link above and get let you know if it works.
    Thanks

    That article only applies to situations where the posts are in more than one category. Your problem sounds different, and I do not have any suggestions.

    Sorry.

    i think the value is “TRUE” not “true” ………

    <?php next_post_link(‘%link’, ‘Next’, TRUE); ?>

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘next_post_link / previous_post_link, in_same_cat=1, not working.’ is closed to new replies.