WordPress.org

Ready to get started?Download WordPress

Forums

Category Next and Previous Links (5 posts)

  1. Oscar
    Member
    Posted 4 years ago #

    I am looking to put in the sidebar of my template navigation links for the category the post is found in. Many of my posts have 2 or more categories and I would like to show the Category and then have next previous links for that specific category.

    Example:
    Post A is found in Cat 1 and Cat 2

    so in the sidebar would be (below):

    Cat 1
    previous post - next post

    Cat 2
    previous post - next post

    ----------------------------------------------------------

    <?php next_post_link('%link', 'Next post in category', TRUE); ?>

    I found the above code in the codex. However this code does not seem to differentiate when there is 2 or more categories assigned to a post.

    Is there a plug-in? I have been searching to no avail. I am wondering if a loop can be created with the above code and use a get category type command.

  2. CallUp
    Member
    Posted 4 years ago #

    I haven't done what you're trying to accomplish, but my first impression is that it might be easier to achieve this if you use subcategories. Such as:

    Arts & Entertainment
    - Music
    - Film
    - Books
    - Theatre

    WordPress seems to handle subcategories pretty well.

  3. Oscar
    Member
    Posted 4 years ago #

    I do utilize subcategories and am very happy with WordPress and the organization.

    I am seeking this as a navigational aid. An example website of this is Flickr when viewing the photo page. I like the way Flickr does navigation on this and am interested in seeing if someone has implemented this. I have read several forum posts regarding this but I can not find a working example. Thanks for any input.

  4. CallUp
    Member
    Posted 4 years ago #

    I haven't tried it, but this might work:

    <?php is_category($category); ?>

    <?php /* If this is a category archive */ if (is_category('Music')) {
    next_post_link('%link', 'Next post in category', TRUE);

    }?>

  5. Oscar
    Member
    Posted 4 years ago #

    Thanks Callup for the response. The code does not seem to work but I was able to use some of code you wrote and manual code it with "if" statements but there must be an easier way.

    This is the manual code written. It must be reproduce with each category that I have.

    <?php if (in_category('39'))
    
    {
    
    echo 'Music';
    
    previous_post_link('%link', '<div>&laquo; &laquo; Previous in category</div>', FALSE, '62 and 38 and 1 and 35 and 30 and 42 and 29 and 69 and 50 and 63 and 52 and 9');
    
    next_post_link('%link', '<div>Next in category &raquo; &raquo;</div>', FALSE, '62 and 38 and 1 and 35 and 30 and 42 and 29 and 69 and 50 and 63 and 52 and 9');
    
    }
    ?>

    This is what I am looking for:

    This post belongs to:

    Music
    Previous Post- Next Post

    Neil Young
    Previous- Next Post

Topic Closed

This topic has been closed to new replies.

About this Topic