在wordpress简码中添加分页

时间:2019-06-27 22:31:54

标签: php wordpress

根据Wordpress Pagination in a Shortcode的建议,我正在为wordpress编写一个简码,并尝试向其添加分页。我快到了,只是不知道为什么wordpress不更新分页的页面内容,例如如果我单击“下一步”或“ 1”,“ 2”,“ 3”等,我总是会看到同一页面。

这是我的代码

<form class="test">
  <div>
    <input class="one" value="one">
    <div>A</div>
  </div>
  <div>
    <input class="two" value="two">
    <div>B</div>
    <div>C</div>
  </div>
</form>

有什么建议吗? :) 谢谢!

1 个答案:

答案 0 :(得分:0)

添加functions.php

// Numbered Pagination
    if ( !function_exists( 'kris_pagination' ) ) {
    	
    	function kris_pagination() {
    		
    		$prev_arrow = is_rtl() ? '→' : '←';
    		$next_arrow = is_rtl() ? '←' : '→';
    		
    		global $wp_query;
    		$total = $wp_query->max_num_pages;
    		$big = 999999999; // need an unlikely integer
    		if( $total > 1 )  {
    			 if( !$current_page = get_query_var('paged') )
    				 $current_page = 1;
    			 if( get_option('permalink_structure') ) {
    				 $format = 'page/%#%/';
    			 } else {
    				 $format = '&paged=%#%';
    			 }
    			echo paginate_links(array(
    				'base'			=> str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
    				'format'		=> $format,
    				'current'		=> max( 1, get_query_var('paged') ),
    				'total' 		=> $total,
    				'mid_size'		=> 3,
    				'type' 			=> 'list',
    				'prev_text'		=> $prev_arrow,
    				'next_text'		=> $next_arrow,
    			 ) );
    		}
    	}
    	
    }

简码

<?php kris_pagination(); ?>