简体   繁体   English

如何显示下一个和上一个分页 wordpress

[英]How to display next and previous pagination wordpress

i want to add next and previous button on my wordpress custom pagination when click next then the previous button does not appear, as well as the previous button and how to give limit page number if the page number is 8 then before ".." same as the screenshoot.我想在单击下一步时在我的 wordpress 自定义分页上添加下一个和上一个按钮,然后上一个按钮不出现,以及上一个按钮以及如果页码为 8 那么在“..”之前如何限制页码相同作为截图。

i want display like this have button next and previous我想要这样的显示有下一个和上一个按钮

在此处输入图像描述

this is my custom function pagination.php这是我的自定义 function pagination.php

<?php
function pagination($pages = '', $range = 2)
{  
     $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='page-navigation red spaced'>";
         if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>&laquo;</a>";
         if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>&lsaquo;</a>";

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

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

and this template pagination和这个模板分页

<div class="page-navigation red spaced">
    <!-- CONTROL PREVIOUS -->
    <div class="slider-control big control-previous">
      <!-- ARROW ICON -->
      <svg class="arrow-icon medium">
        <use xlink:href="#svg-arrow-medium"></use>
      </svg>
      <!-- /ARROW ICON -->
    </div>
    <!-- /CONTROL PREVIOUS -->
    <a href="#" class="page-navigation-item">1</a>
    <a href="#" class="page-navigation-item active">2</a>
    <a href="#" class="page-navigation-item">3</a>
    <a href="#" class="page-navigation-item">...</a>
    <a href="#" class="page-navigation-item">8</a>
    <!-- CONTROL PREVIOUS -->
    <div class="slider-control big control-next">
      <!-- ARROW ICON -->
      <svg class="arrow-icon medium">
        <use xlink:href="#svg-arrow-medium"></use>
      </svg>
      <!-- /ARROW ICON -->
    </div>
    <!-- /CONTROL PREVIOUS -->
  </div>

This code works in archive page.此代码适用于存档页面。 Just change total and current args for another usage只需更改 total 和 current args 以用于其他用途

<div class="pageinate">
                <?php 
                    global $wp_query;
                    
                    echo paginate_links( array(
                        'base'         => str_replace( 999999999, '%#%', esc_url( get_pagenum_link( 999999999 ) ) ),
                        'total'        => $wp_query->max_num_pages,
                        'current'      => max( 1, get_query_var( 'paged' ) ),
                        'format'       => '?paged=%#%',
                        'show_all'     => false,
                        'type'         => 'plain',
                        'end_size'     => 2,
                        'mid_size'     => 1,
                        'prev_next'    => true,
                        'prev_text'    => sprintf( '<', __( 'Newer Posts', 'text-domain' ) ),
                        'next_text'    => sprintf( '>', __( 'Older Posts', 'text-domain' ) ),
                        'add_args'     => true,
                        'add_fragment' => '',
                    ) );
                ?>
            </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 WordPress链接分页仅显示下一个和上一个按钮 - Wordpress Link Pagination to display only next and previous buttons 如何使用分页在自定义WordPress循环中添加下一个和上一个链接 - How to add next and previous links in custom WordPress loop with pagination 如何在WordPress-&gt;分页-&gt; previous \\ next_posts_link中将绝对URL更改为相对URL? - How can I change absolute URL to relative in WordPress -> pagination -> previous\next_posts_link? 如何将PHP代码放入wordpress分页功能(previous_post_link,next_post_link等)中? - How to put PHP code in wordpress pagination function (previous_post_link,next_post_link,etc)? Wordpress分页导航:如何使“下一页”和“上一页”保持不变? - Wordpress pagination navigation: how do I make 'Next Page' and 'Previous Page' persist? WordPress:显示带有下一个和上一个链接的孙页面 - Wordpress: Display grandchild pages with Next and Previous link 始终使用 Wordpress 中的_post_pagination 显示下一个/上一个 - Always show Next/Previous using the_post_pagination in Wordpress 如何给分页的上一个和下一个按钮? - How to give previous and next button in pagination? 如何使用下一个和上一个按钮创建分页? - how to create pagination with next and previous button? 下一个,如何使用CakePHP添加分页号 - How to add Pagination numbers, next, previous with CakePHP
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM