WordPress.org

Forums

[resolved] Excluding categories from next_posts_link (6 posts)

  1. Yukon Cornelius
    Member
    Posted 4 years ago #

    Hi,

    I am trying to exclude posts from two categories from showing in my previous/next navigation links with the following code, but post in 8 and 62 still seem to be showing.
    `<div class="navigation">
    <div class="next-posts"><?php next_posts_link('« Older Entries', '%title', FALSE, '8 and 62') ?></div>
    <div class="prev-posts"><?php previous_posts_link('« Older Entries', '%title', FALSE, '8 and 62') ?></div>
    </div>`

    Can anyone see where I'm going wrong?

    Thanks,

    Jimmy

  2. Michael
    Forum Moderator
    Posted 4 years ago #

    you have the functions for the next/prev posts on multipost pages:
    http://codex.wordpress.org/Function_Reference/next_posts_link
    http://codex.wordpress.org/Function_Reference/previous_posts_link

    these functions do not have the parameters you are trying to apply.

    if you are working on the next/prev of single post,
    then the functions would be:
    http://codex.wordpress.org/Function_Reference/next_post_link
    http://codex.wordpress.org/Function_Reference/previous_post_link

  3. Yukon Cornelius
    Member
    Posted 4 years ago #

    Thanks Alchymyth!

  4. the red bicycle
    Member
    Posted 4 years ago #

    I found the above usefull to a certain point..Is it possible to limit the categories excluded using a query

    <?php
    if ( is_cat=1() ) {
    query_posts( 'cat=-2,-3' )
    if ( is_cat=2() ) {
    query_posts( 'cat=-1,-3' )
    if ( is_cat=3() ) {
    query_posts( 'cat=-1,-2' )

    I would like to use this to include only posts from the same category from showing up in the single post template next/previous link.

    Thanks a bucket

  5. Michael
    Forum Moderator
    Posted 4 years ago #

    same category from showing up in the single post template next/previous link.

    http://codex.wordpress.org/Function_Reference/next_post_link
    http://codex.wordpress.org/Function_Reference/previous_post_link

    'in_same_cat' paramter

    conditional tags
    http://codex.wordpress.org/Conditional_Tags

    (is_category() would not work in single.php; try in_category() )

  6. the red bicycle
    Member
    Posted 4 years ago #

    I found the documentation for next_post_link very usefull. Made me thank Wp for being so adaptable. And thanks to you for your response.

Topic Closed

This topic has been closed to new replies.

About this Topic