• Resolved Michael Rieder

    (@teamtacho)


    Hi Amit

    Please can you guide me what I have to change in order to get the previous/next blog navigation within the choosen category/tag or author.

    Best Regards

Viewing 8 replies - 1 through 8 (of 8 total)
  • Hi,

    On archive pages, you can set standard pagination or infinite scroll. For the next and previous pagination styles, you have to add custom code. On a single post or page, you can see the next or previous post/page option. Let me know if I didn’t understand your query clearly.

    Thread Starter Michael Rieder

    (@teamtacho)

    Hi Amid

    Thanks for the response. What I want to achive is the following explanation:

    I select a category and get all posts relatet to that category as a list.

    Then I select one post and get the post as a single post with previous/next arrows with other posts

    these other posts don’t stay in the specific category.

    Hi,

    Kindly go to Customize > Blog > Single Post > Single Post Options and select Category from Next/Prev Post Taxonomy settings.

    This will make the pagination as you want.

    Thread Starter Michael Rieder

    (@teamtacho)

    Hi Amit

    I made the settings, but the previous/next navigation is not correct.

    e.g. https://teamtacho.de/balcone-turino-2025/

    Please find a link to a visual description https://www.dropbox.com/scl/fo/v6nooqcc32lgzel0hr2ch/AALHd7jdr0QlcPdp5_7UM5Q?rlkey=sc01p19fvmd8xc3yscvcs91z9&st=dugumle8&dl=0

    Hi,

    It is because your current post fall into both categories, therefore it is showing posts from both categories.

    Thread Starter Michael Rieder

    (@teamtacho)

    Hi Amit

    would it be possible to navigate only within the primary category. This would solve my issue.

    Amit Singh

    (@apprimit)

    Hi,

    You can try the below code. Try it on a staging site and take site backup before that. You can add code using child theme.

    function prefix_parent_category_navigation( $where, $in_same_term ) {

        if ( ! is_singular( 'post' ) ) {

            return $where;

        }

        if ( ! $in_same_term ) {

            return $where;

        }

        $categories = get_the_category();

        if ( empty( $categories ) ) {

            return $where;

        }

        $cat = $categories[0];

        while ( $cat->parent != 0 ) {

            $cat = get_category( $cat->parent );

        }

        $parent_id = $cat->term_id;

        global $wpdb;

        $where .= $wpdb->prepare(

            " AND tt.term_id = %d ",

            $parent_id

        );

        return $where;

    }

    add_filter( 'get_previous_post_where', 'prefix_parent_category_navigation', 10, 2 );
    add_filter( 'get_next_post_where', 'prefix_parent_category_navigation', 10, 2 );
    Thread Starter Michael Rieder

    (@teamtacho)

    Hi Amit

    thank you very much. I will test it.

Viewing 8 replies - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.