WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Problem with previous_post_link and next_post_link (9 posts)

  1. dubbinz
    Member
    Posted 1 year ago #

    I am using the following lines of code in my single.php which is working great however I have 1 category that uses single.php that I do not want these to display on. I have no idea how to go about doing this.

    <?php previous_post_link( '<div class="nav-prev">%link</div>', 'Previous', TRUE ); ?>
    <?php next_post_link( '<div class="nav-next">%link</div>', 'Next', TRUE ); ?>

    I tried using this

    <?php previous_post_link( '<div class="nav-prev">%link</div>', 'Previous', TRUE, '3'); ?>
    <?php next_post_link( '<div class="nav-next">%link</div>', 'Next', TRUE, '3'); ?>

    but it is still displaying the links in the category with the ID of 3 which is the category I do not wish to display these links in. So now I am confused and do not know how to hide these links.

    Can anybody help?

  2. vjpo
    Member
    Posted 1 year ago #

    <?php if( ! in_category(3) ) :
    previous_post_link( '<div class="nav-prev">%link</div>', 'Previous', TRUE );
    next_post_link( '<div class="nav-next">%link</div>', 'Next', TRUE );
    endif; ?>

    Also could be useful Next post link within same category, excluding one.

  3. dubbinz
    Member
    Posted 1 year ago #

    @vjpo I'll try it thanks

  4. dubbinz
    Member
    Posted 1 year ago #

    @vjpo it unfortunately doesn't seem to be having any effect, any other ideas? Also the snippets I shown were based on Next post link within same category, excluding one.

    I'm completely stumped with this.

  5. dubbinz
    Member
    Posted 1 year ago #

    @vjpo aha it does work with one category but I tried doing this

    <?php if( ! in_category('335,336,334') ) :
    previous_post_link( '<div class="nav-prev">%link</div>', 'Previous', TRUE );
    next_post_link( '<div class="nav-next">%link</div>', 'Next', TRUE );
    endif; ?>

    I needed 3 categories to hide the links, I am guessing I did this wrong..

  6. vjpo
    Member
    Posted 1 year ago #

    Multiple categories is an array :)
    <?php if( ! in_category( array( 335, 336, 334 ) )) :
    or
    <?php if( ! in_category( array( 'one', 'two' ) )) :

    in_category example

  7. dubbinz
    Member
    Posted 1 year ago #

    @vjpo thanks for the help much appreciated

  8. dubbinz
    Member
    Posted 1 year ago #

    this has been resolved.

  9. vjpo
    Member
    Posted 1 year ago #

    You are welcome :)

Topic Closed

This topic has been closed to new replies.

About this Topic