php - Pagination - Previous link is not show and Next link sticks at page 2

admin2025-06-01  2

The code below is not able to show the pagination correctly

  1. Previous link is not able to show
  2. Page 1 is not a link
  3. Next Button always sticks with page 2

Thanks

<?php


if ( have_posts() ):
    $current_lang = pll_current_language();
    $query_array = array(
        'post_type' => $custom_post_type,
        'paged' => $paged,  
        'posts_per_page' => 5,  
        'meta_query' => array(
            'order_clause' => array(
                'key' => 'wpcf-publish-date',
                'compare' => 'EXISTS'
            ),
        ),
        'orderby' => array(
            'order_clause' => 'DESC'
        )
    );



    $query_object = new WP_Query($query_array);
    $posts = [];
    $month_year_arr = [];
    while ($query_object->have_posts()){
        $query_object->the_post();
        $date = types_render_field('publish-date', array('output'=>'raw', 'format'=>'U'));
        switch ($current_lang) {
        case 'en':
            $month_year = date('M Y', $date);
         break;
        case 'zh_hant':
            $month_year = date('Y年n月', $date);
             break;
        case 'zh_hans':
            $month_year = date('Y年n月', $date);
            break;
        }



        $myindex = date("Ym", $date);
        array_push($posts, [
            'doc_name' => types_render_field('doc-name-'.$current_lang, array('output'=>'raw')),
            'file_url' => types_render_field('file-addr-'.$current_lang, array('output'=>'raw')),
            'publish_date' => $date,
            'month_year' => $myindex
        ]);
        if(!$month_year_arr[$myindex]) $month_year_arr[$myindex] = $month_year;
    }
?>
     <div class="container-fulid irContent">
        <div class="container indexTbl">
            <div class="indexTblInner">
                <div class="row">
                    <div class="col-lg-12">
                        <div class="ir-title"><?php echo pll_e('Corporate Governance'); ?></div>
                    </div>
                </div>

                <div class="row ir-sor">
                    <div class="col-xs-12 col-sm-7 col-md-4 col-lg-3"><?php echo pll_e('Sorting by year'); ?>
                        <div class="dropdown selYearItem">
                            <button class="dropdown-toggle selYearItem sortByYear" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false" style="width: 100px;">All<span class="caret"></span></button>
                            <ul class="dropdown-menu selectYear" aria-labelledby="sortByYear" align="center">
                                <li style="margin-left:5px"><span selYear="All">All</span></li>
                                <?php
                                    foreach ($month_year_arr AS $id => $val) : 
                                        echo '<li style="margin-left:5px"><span selYear="'.$id.'">'.$val.'</span></li>';
                                    endforeach;


                                ?>
                            </ul>
                        </div>
                    </div>
                </div>


                <div class="row">
                    <div class="col-xs-12 col-sm-7 col-md-8 col-lg-9">
                        <div class="irLeft"><?php echo pll_e('Document'); ?></div>
                    </div>
                    <div class="col-xs-6 col-sm-5 col-md-4 col-lg-3 irDateTitle">
                        <div class="irRight"><?php echo pll_e('Publication Date'); ?></div>
                    </div>
                    <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
                        <div class="irUnderborder"></div>
                    </div>
                    <div class="irImg_hover"></div>
                </div>
<?php

                foreach ($posts as $post) :
                    $doc_name = $post['doc_name'];
                    $file_url = $post['file_url'];
                    $publish_date = $post['publish_date'];
                    $month_year_index = $post['month_year'];
?>
                <div class="row rowDoc" data-monthyear="<?php echo $month_year_index; ?>">
                    <div class="col-xs-12 col-sm-7 col-md-8 col-lg-9 irIngR">
                        <a href="<?php echo $file_url; ?>" target="_blank"><div class="irImg"><?php echo $doc_name;?></div></a>
                    </div>
                    <div class="col-xs-12 col-sm-5 col-md-4 col-lg-3 irDate">
                        <?php 
                            switch ($current_lang) {
                            case 'en':
                                echo date('d M Y', $publish_date);
                            break;
                            case 'zh_hant':
                                echo date('Y年n月d日', $publish_date);     
                            break;
                            case 'zh_hans':
                                echo date('Y年n月d日', $publish_date); 
                            break;
                            }

                        ?>

                    </div>
                    <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
                        <div class="irContentUnderborder"></div>
                    </div>

                </div>
                    <?php
                        endforeach;

                    ?>
            </div>

            <div>
    <?php

            $paged = (get_query_var('page')) ? get_query_var('page') : 1;  


            $total_pages = $query_object->max_num_pages;

            if ($total_pages > 1){

            $current_page = max(1, get_query_var('page'));

            echo paginate_links(array(
                'base' => get_pagenum_link(1) . '%_%',
                'format' => 'page/%#%',
                'current' => $current_page,
                'total' => $total_pages,
                'prev_next'    => True,
                'prev_text'    => __('<< Prev'),
                'next_text'    => __('Next >>'),
            ));
        }
        wp_reset_postdata();    
    ?> 

                    </div>



        </div>
     </div>

      <script type="text/javascript">
        jQuery(document).ready(function(){
            jQuery(".rowDoc").hover(
                function(){jQuery(this).children("div").children("a").children("div").addClass("irImg_hover");jQuery(this).children(".irDate").addClass("irDate_hover");},
                function(){jQuery(this).children().children("a").children("div").removeClass("irImg_hover");jQuery(this).children(".irDate").removeClass("irDate_hover");}
            );
        });
        jQuery(document).ready(function(){
            jQuery(".selectYear li").click(function() {
                var yearVal = jQuery(this).children("span").attr("selYear");
                var yearValText = jQuery(this).children("span").html();
                jQuery(".sortByYear").html(yearValText + '<span class="caret"></span>');
                jQuery(".irContent .indexTbl .indexTblInner .rowDoc").removeClass("hideRow");
                if (yearVal != 'All')
                {
                    jQuery(".irContent .indexTbl .indexTblInner .rowDoc[data-monthyear!="+yearVal+"]").addClass("hideRow");
                }
             });
         });



    </script>
<?php
endif;
?>
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748793181a313763.html

最新回复(0)