简体   繁体   中英

Wordpress numeric pagination without words

My work's Wordpress site needs a numeric pagination for the posts page, however as it's a multilingual site I can't have any words in it like "Previous page" or "Page 1 of 3".

I've tried a couple of different examples that I've found (as I'm not skilled enough to write it myself yet), but they all contain words hidden within queries and I can't figure out how to change them. Eg:

function pagination($pages = '', $range = 4)
{  
     $showitems = ($range * 2)+1;  

     global $paged;
     if(empty($paged)) $paged = 1;

     if($pages == '')
     {
         global $wp_query;
         $pages = $wp_query->max_num_pages;
         if(!$pages)
         {
             $pages = 1;
         }
     }   

     if(1 != $pages)
     {
         echo "<div class=\"pagination\"><span>Page ".$paged." of ".$pages."</span>";
         if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>&laquo; First</a>";
         if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>&lsaquo; Previous</a>";

         for ($i=1; $i <= $pages; $i++)
         {
             if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
             {
                 echo ($paged == $i)? "<span class=\"current\">".$i."</span>":"<a href='".get_pagenum_link($i)."' class=\"inactive\">".$i."</a>";
             }
         }

         if ($paged < $pages && $showitems < $pages) echo "<a href=\"".get_pagenum_link($paged + 1)."\">Next &rsaquo;</a>";  
         if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>Last &raquo;</a>";
         echo "</div>\n";
     }
}

This code shows "Page 1 of 2". If I could just change that to 1/2 for example, that would be perfect. Is anyone able to explain how I could do this, or any alternative methods? Many thanks!

Check out below code for Wordpress numeric pagination custom code:

<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
if ($paged == "1") {
    $args = array(
        'post_type' => 'uk-blog',
        'post_status' => 'publish',
        'offset' => 0,
        'posts_per_page' => 10
    );
} else {
    $offset = $paged * 5;
    $offset = $offset - 5;
    $args = array(
        'post_type' => 'uk-blog',
        'post_status' => 'publish',
        'offset' => $offset
    );
}

$loop = new WP_Query($args);
if ($loop->have_posts()) :
while ($loop->have_posts()) : $loop->the_post();
    /*Your Code */

endwhile;
?>
<div class="pagination-grp">
    <?php
    $big = 999999999; // need an unlikely integer
    //$i=1;

    echo paginate_links(array(
        'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
        'format' => '?paged=%#%',
        'current' => max(1, get_query_var('paged')),
        'prev_text' => __('<'),
        'next_text' => __('>'),
        'total' => $loop->max_num_pages

    ));
    wp_reset_postdata();
    endif;
    ?>
</div>

Please find the code :

    function theme_pagination()
    {
        echo paginate_links( array(
           'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
           'format' => '?paged=%#%',
           'type'=>'list',
           'current' => max( 1, get_query_var('paged') ),
           'total' => $wp_query->max_num_pages,
           'prev_text'    => '',
           'next_text'    => '',
        ));

    }

Hope this will do the work

In the end I just isolated the text that said "Page 1 of 2" and gave it a display:none; style. Not really a solution but it works for this project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM