I want the “next” and “previous” buttons to appear in my custom navigation function

enter image description here

I’m looking for a way to display the two buttons “previous” and “next” of the navigation of my page, but with the code below, I can only show one, I do not understand what’s wrong in the code (below):

<div class="cover--nav">
        <?php
            $currenttPostId = get_the_ID();
            $theCategory = get_the_terms(get_the_ID(),'recipe_category');

                global $wp_query;


                $args = array(
                    'post_type' => 'recipe',
                    'orderby' => 'rand',
                    'post_status' => 'publish',
                    'recipe_category'=> !empty($theCategory)? $theCategory[0]->slug : '',
                    'post__not_in' => array($currenttPostId), 
                    'posts_per_page' => 2,
                    'paged' => $paged  //very important
                );
                $wp_query = new WP_Query($args);


                $prevNext = array();

                if ( $wp_query->have_posts() ) :
                    while ( $wp_query->have_posts() ) : $wp_query->the_post();
                        the_title();
                    endwhile;
                endif;


                wp_reset_postdata();


                $prev_label = "<span class='cover--nav-label'>" . _e('Recette précédente', 'marque') . "</span>";

                $prev_arrow = "<svg class='icon icon-arrow-prev' role='presentation' focusable='false'><use xlink:href='" . get_template_directory_uri() . "/images/symbol-defs.svg#icon-arrow-prev'></use></svg>";

                $prev_text = $prev_label . $prev_arrow;



                $next_label = "<span class='cover--nav-label'>" . _e('Recette suivante', 'marque') . "</span>";

                $next_arrow = "<svg class='icon icon-arrow-next' role='presentation' focusable='false'><use xlink:href='" . get_template_directory_uri() . "/images/symbol-defs.svg#icon-arrow-next'></use></svg>";

                $next_text = $next_label . $next_arrow;

                the_posts_navigation( array(
                'prev_text' => $prev_text,
                'next_text' => $next_text,
                ) );



                ?>

        </div>

That’s what happens:

I would like to get the example below:

Read more here:: I want the “next” and “previous” buttons to appear in my custom navigation function

Leave a Reply

Your email address will not be published. Required fields are marked *