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

by Frenchy_WP   Last Updated February 11, 2019 09:08 AM - source

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">
            $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();


                $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,
                ) );



This is what happens:

enter image description here

I would like to get the example below:

enter image description here

Answers 1

The _e function immediately echoes the translated content to the output queue, so the string will end up in the html early. If you simply want to retrieve the translated content to add it to a string you need __.

February 11, 2019 08:46 AM

Related Questions

Override the WordPress default pagination markup

Updated August 14, 2018 09:08 AM

the_posts_navigation is not working

Updated July 13, 2017 02:08 AM