doufei1852 2017-09-25 10:33
浏览 73

wordpress自定义分页功能 - 显示空白页面

My custom pagination function returns empty pages at the end. It doesn't check when the loop ends, and does not stop counting pages - blank pages at the end - counting empty result? Ive try to add optional parameters and other things, but it still not working how i want. here is the problem - few empty pages

function custom_pagination($numpages = '', $pagerange = '2', $paged='') {

  if (empty($pagerange)) {
    $pagerange = 2;
  }

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

 if ( is_home() ) {
 $format = '?paged=%#%';
 } else if ( !get_option('permalink_structure') ) {
 $format = '&paged=%#%';
 } else {
 $format = 'page/%#%/';
 }

  $pagination_args = array(
    'base'  => @add_query_arg('paged','%#%'),
    'format'       => '',
    'total'           => $numpages,
    'current'         => $paged,
    'show_all'        => False,
    'end_size'        => 1,
    'mid_size'        => $pagerange,
    'prev_next'       => True,
    'prev_text'       => __('«'),
    'next_text'       => __('»'),
    'type'            => 'plain',
    'add_args'        => false,
    'add_fragment'    => ''
  );

  $paginate_links = paginate_links($pagination_args);



  if ($paginate_links) {
    echo "<nav class='custom-pagination'>";
      echo "<span class='page-numbers page-num'><a class='showing_pages'>Showing Page " . $paged . " of " . $numpages . "</a></span> <span class='page_numbers'>";
      echo $paginate_links;
    echo "</span></nav>";
  }
}

Here i call this function:

              $quert    = array(
                    'relation' => 'AND',
                    array(
                        'relation' => 'OR',
                        array(
                            'key'       =>'subject',
                            'value'     => $_GET['subject'],
                            'compare'   => 'LIKE',
                        ),
                        array(
                            'key'       => 'job_type',
                            'value'     =>  $_GET['job_type'],
                            'compare'   => 'LIKE',
                        ),
                        array(
                            'key'       => 'job_title',
                            'value'     => $_GET['job_title'],
                            'compare'   => 'LIKE'
                        ),
                    ),
                    array(
                        'key'       => 'location',
                        'value'     => $_GET['location'],
                        'compare'   => 'LIKE',
                    )
                    );

                /*$startdate = get_field("start_date");
                $startdate = get_field("start_date");*/
            /*    $number_of_jobs_on_each_page= 12;*/

             $number_of_jobs_on_each_page=get_field("number_of_jobs_on_each_page");
                $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
                /*$date = date_create($stdate);
                echo date_format($date, 'Ymd');*/
                $custom_args = array(
                    'post_type'         =>  array( 'job' ),
                    'order'             =>  'DESC',
                    'orderby'           =>  'post_date',
                    'posts_per_page'    => $number_of_jobs_on_each_page,
                    'paged'             => $paged,
         /*           'meta_key'          => 'start_date',
                    'meta_type'         => 'DATE',
                    'orderby'           => 'meta_value_num',
                    'order'             => 'ASC',*/
                    'meta_query' => $quert,
                    );

                $custom_query = new WP_Query( $custom_args );
                if (function_exists(custom_pagination)) {
                    custom_pagination($custom_query->max_num_pages,"",$paged);
                }
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 对于squad数据集的基于bert模型的微调
    • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
    • ¥20 steam下载游戏占用内存
    • ¥15 CST保存项目时失败
    • ¥15 树莓派5怎么用camera module 3啊
    • ¥20 java在应用程序里获取不到扬声器设备
    • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
    • ¥15 Attention is all you need 的代码运行
    • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
    • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事: