Forums

Using next/previous_post within the same category (4 posts)

  1. animerest
    Member
    Posted 1 year ago #

    Hello,

    i don't know much about wordpress, but i am trying to set up a decent anime site. My question is if its possible to add category function in the next/previous_post command, so that only post within the same category will be shown. The code that i am currently using o my site is
    -'next_link' => theme_get_previous_post_link('« %link' )
    -'prev_link' => theme_get_next_post_link('%link »' )

    Any ideas on how to add the same category command if its possbile ?

    Thanks in advance (=,
    Gregor Kristan

  2. zimmi88
    Member
    Posted 1 year ago #

    Check out the template tag previous_post_link(). The third parameter in the set allows you to specify whether the previous post that it links to should be from the same category - set to true to enable this feature. A similar tag exists for next post as well.

    I hope this helps!

  3. animerest
    Member
    Posted 1 year ago #

    Yes that helped thanks (=, but now i have another problem, my previous and next post links are the same, meaning they lead to the same post: here is the code i was editing

    if (!function_exists('theme_get_previous_post_link')){

    function theme_get_previous_post_link($format='« %link', $link='%title', $in_same_cat = true, $excluded_categories = '') {
    return theme_get_adjacent_post_link($format, $link, $in_same_cat = true);
    }
    }

    if (!function_exists('theme_get_next_post_link')){
    function theme_get_next_post_link($format='%link »', $link='%title', $in_same_cat = true, $excluded_categories = '') {
    return theme_get_adjacent_post_link($format, $link, $in_same_cat = true);
    }
    }

  4. zimmi88
    Member
    Posted 1 year ago #

    Well, it looks like whatever theme-specific implementation of previous_post_link that you're using calls the same function for getting an adjacent post, so unless that function has another parameter for specifying whether to get the previous post or next post, I'm not sure how it would be distinguishing between previous and next post. I'd take a look further at the theme_get_adjacent_post_link method and see if there's any missing parameters or some other way to distinguish between a previous post and next post. If not, you can try falling back to the methods that are built in to WordPress.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.