WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] WordPress Next/Prev Navigation for child category (7 posts)

  1. apple10
    Member
    Posted 1 year ago #

    Hi i have a wordpress web site with the category structure as below

    Lessons ( Parent )
    --Guitar Training ( Child Of Lessons )
    --Keyboard Training ( Child Of Lessons )
    --Vocal Training ( Child Of Lessons )

    What i exactly need is to stay in the same child category when navigating using next/prev buttons. i do not want the next/prev buttons to take the user to an other child category. To be more specific if the user is browsing the Vocal Training course, i need the prev/links to stay in the same category. But the problem is the previous/next_post_link in single.php does not stay in a category.

    So as the WP Codex Says i tried

    <?php get_next_post( $in_same_cat, $excluded_cats ) ?>

    But it does not work since the posts are always linked to multiple categories in my case (eg: Lessons, Guitar Training ). Is their any way to stay in the child category ? in this case only within Guitar Training ?

    Thank you.

  2. vjpo
    Member
    Posted 1 year ago #

    If to assign post only to child category (e.g. to Guitar Training, not to Lessons), it must work as you wish.

  3. apple10
    Member
    Posted 1 year ago #

    @vjpo
    I know but the post must be in multiple categories else i wouldn't have posted this support thread. Thanks for the quick response :)

  4. vjpo
    Member
    Posted 1 year ago #

    Do you mean in multiple child categories? There is no need to assign post to parent cat (post already in it's archive since it assigned to children category).
    But, if it must be assigned to multiple children equal cats, The problem can be resolved, with custom fields or some plugin like this
    http://wordpress.org/extend/plugins/ambrosite-nextprevious-post-link-plus/

    I haven't exact answer right now, perhaps you will provide some detailed example according to what order post links must be chosen.

  5. apple10
    Member
    Posted 1 year ago #

    @vjpo
    Thank you for the response,

    Well let me explain the scenario, like i mentioned

    Lessons ( Parent )
    --Guitar Training ( Child Of Lessons )
    --Keyboard Training ( Child Of Lessons )
    --Vocal Training ( Child Of Lessons )

    Every child category has around 20 posts which are tutorials. i don't want the prev/next buttons to go beyond the child category that i have selected. if the course is in (Lessons,Guitar Training) , i want the prev/next links to only navigate in the same "Guitar Training" child category.

    I Hope you understood the question :-)
    Thank you for the kind & quick response

  6. vjpo
    Member
    Posted 1 year ago #

    apple10 So, if there are no multiple, same depth children categories, only unselect the Lessons category when editing post. And this construction will show only link to same cat posts.
    <?php next_post_link('%link', '←', TRUE); ?>
    I am using this structure and it works well.

  7. apple10
    Member
    Posted 1 year ago #

    @vjpo
    Thank you very much sir, i had a custom template for Lessons and that's why i wanted to select the both child category of the Lessons and the category it self.

    i managed to tweak the coding a bit to get my function to get the catch the parent category and apply the lessons template.

    Thank you again for the kind reply and awesome solution.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags