亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在產品帖子上添加分頁號碼

在產品帖子上添加分頁號碼

PHP
大話西游666 2021-06-14 12:29:23
所以這是網站.. https://chicafriqfashion.com/和像https://chicafriqfashion.com/fabrics/這樣的頁面之一在頁面上有產品。我能夠在底部添加分頁,但它只是上一頁和下一頁。我需要它來顯示頁碼。請幫忙。這是開始<?php        $args = array( 'post_type' => 'product', 'stock' => 1, 'product_cat' => 'earrings-ring', 'posts_per_page' => '12','order' => 'DESC', 'paged' => $paged );        $loop = new WP_Query( $args );        while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>這是我的分頁代碼<h3>Pages:  <?php previous_posts_link( '&laquo; PREV', $loop->max_num_pages) ?>            <?php next_posts_link( 'NEXT &raquo;', $loop->max_num_pages) ?> </h3></div><?php wp_reset_postdata(); ?>
查看完整描述

2 回答

?
慕桂英4014372

TA貢獻1871條經驗 獲得超13個贊

解決方案-1(存檔頁面)

首先獲取要傳入 Wp_Query 參數的當前頁面。


        // current page

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


        // prepare arguments

        $args = array( 'post_type' => 'product',

       'stock' => 1,

       'product_cat' => 'earrings-ring',

       'posts_per_page' => '12',

       'order' => 'DESC',

       'paged' => $paged 

       );


        //prepare query

        new WP_Query( $args ); 

您應該在 wp_reset_postdata() 之前調用 WordPress 分頁函數


            the_posts_pagination( array(

                'prev_text'          => '<span class="fa fa-angle-left" aria-hidden="true"></span>',

                'next_text'          => '<span class="fa fa-angle-right" aria-hidden="true"></span>',

                'screen_reader_text' => '&nbsp;',

                'before_page_number' => '',

                'mid_size'    => 3,

            ) );

解決方案-2(自定義模板)

構造 Wp 查詢


        // prepare arguments

        $args = array( 'post_type' => 'product',

       'stock' => 1,

       'product_cat' => 'earrings-ring',

       'posts_per_page' => '12',

       'order' => 'DESC',

       'paged' => $paged 

       );


        //prepare query

        $query = new WP_Query( $args );

        $totalPage=$query->max_num_pages;

調用分頁功能


                $big = 999999999; // need an unlikely integer

                echo paginate_links( array(

                    'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),

                    'format' => '?paged=%#%',

                    'current' => max( 1, get_query_var('paged') ),

                    'total' => $totalPage

                ) );

此解決方案適用于自定義頁面模板。您可以查看 wordpress 官方文檔。


查看完整回答
反對 回復 2021-06-19
?
Smart貓小萌

TA貢獻1911條經驗 獲得超7個贊

在活動主題function.php文件中添加以下代碼。

注意:如果您有子主題,請在子主題function.php文件中添加此代碼


if ( ! function_exists( 'number_pagination' ) ) :

    function number_pagination() {

        global $wp_query;


        $big = 999999999; 


        echo paginate_links( array(

            'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),

            'format' => '?paged=%#%',

            'current' => max( 1, get_query_var('paged') ),

            'total' => $wp_query->max_num_pages

        ) );

    }

endif;

在要顯示數字分頁的位置添加以下代碼。


<?php number_pagination( $loop ); ?>

</div>


查看完整回答
反對 回復 2021-06-19
  • 2 回答
  • 0 關注
  • 192 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號