• Hello,

    I need to perform an IF statement to check if there is a next post inside ‘the loop’ and, if true, display the next_post_link(). But I’m unsure on the IF statement condition?

    Anyone?

    Ty.

Viewing 3 replies - 1 through 3 (of 3 total)
  • This might work:

    $in_same_cat = false;
    $excluded_cats = '';
    $previous = false;
    if (get_adjacent_post($in_same_cat,$excluded_cats,$previous)) {
       // display next_post_link
    }
    Thread Starter Nith

    (@nith)

    Yeah, worked great.

    <div id="post-nav">
    	<p class="previous_post">
    		<?php if(get_adjacent_post(true, '', true)) { ?>
    			<b>Previous: </b> <?php previous_post_link('%link','%title',true); ?>
    		<?php } ?>
    	</p>
    	<p class="next_post">
    		<?php if(get_adjacent_post(true, '', false)) { ?>
    			<b> :Next</b> <?php next_post_link('%link','%title',true); ?>
    		<?php } ?>
    	</p>
    </div>

    Cheers.

    Glad it worked! But, I am curious – would this work without the call to get_adjacent_post?

    <?php previous_post_link('<b>Previous: </b>%link','%title',true); ?>

    If so, it would save 2 database accesses.
    `

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Check if there is a next_post_link()’ is closed to new replies.