簡體   English   中英

WordPress分頁靜態頁面

[英]Wordpress pagination static page

我正在使用Wordpress模板,並希望使用靜態頁面作為主頁。 我在該頁面上進行了分頁,但是當我轉到另一個頁面時,URL會更改,並且還會顯示另一個頁面的帖子,但是分頁的當前頁面是相同的。 它說它仍在分頁的“ ..頁1”上。

有人知道我如何更改當前頁面嗎?

 function custom_pagination($numpages = '', $pagerange = '', $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; } } $pagination_args = array( 'base' => get_pagenum_link(1) . '%_%', 'format' => 'page/%#%', 'total' => $numpages, 'current' => $page, 'show_all' => False, 'end_size' => 1, 'mid_size' => $pagerange, 'prev_next' => True, 'prev_text' => __('&laquo;'), 'next_text' => __('&raquo;'), 'type' => 'plain', 'add_args' => false, 'add_fragment' => '' ); $paginate_links = paginate_links($pagination_args); if ($paginate_links) { echo "<span class='page-numbers page-num'>Page " . $page . " of " . $numpages . "</span> "; echo $paginate_links; } } 
 <?php $paged = ( get_query_var('page') ) ? get_query_var('page') : 1; $query_args = array( 'post_type' => 'post', 'posts_per_page' => 12, 'paged' => $paged, 'page' => $paged ); $the_query = new WP_Query( $query_args ); ?> <?php if ( $the_query->have_posts() ) : ?> <!-- the loop --> <?php while ( $the_query->have_posts() ) : $the_query->the_post(); // Get all posts get_template_part( 'content', 'post' ); endwhile; ?></div> <!-- end of the loop --> <nav class='paging-navigation'> <?php if (function_exists(custom_pagination)) { custom_pagination($the_query->max_num_pages,"",$paged); } ?></nav> <?php wp_reset_postdata(); ?> <?php else: ?> <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p> <?php endif; ?></div> 

解決了問題! 把這個:

<?php
  if (function_exists(custom_pagination)) {
    custom_pagination($the_query->max_num_pages,"",$paged);
  }

在wp_reset_postdata之后,還從$ query_args中刪除了'page'=> $ paged,這對我有用。 :)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM