【问题标题】:pagination numeric Custom post types wordpress分页数字自定义帖子类型wordpress
【发布时间】:2017-06-04 20:43:37
【问题描述】:

有人知道我如何在 wordpress 中使用自定义帖子类型进行数字分页吗?

$posts_per_page = 10;
$post_type = 'products'

$args = array( 'post_type'=> $post_type, 'posts_per_page' => $posts_per_page, 'paged' => get_query_var('paged') );

query_posts( $args );

【问题讨论】:

    标签: wordpress


    【解决方案1】:
    $args = array( 'post_type'=> $post_type, 'posts_per_page' => $posts_per_page, 'paged' => get_query_var('paged') );
    
    $the_query = new WP_Query( $args);
     //Your post loop goes here...
     //Get the posts and show your post datas however you want;
    

    当你收到帖子后,试试下面的代码进行分页

     $big = 999999999; // need an unlikely integer
    
     echo paginate_links( array(
     'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
     'format' => '?paged=%#%',
     'current' => max( 1, get_query_var('paged') ),
     'total' => $the_query->max_num_pages
     ) );
    
    wp_reset_postdata();
    

    可以找到类似的解决方案here.

    【讨论】:

      猜你喜欢
      • 2014-05-15
      • 2011-03-20
      • 2014-05-21
      • 1970-01-01
      • 1970-01-01
      • 2017-10-14
      • 2016-08-08
      • 2012-11-29
      • 2013-06-22
      相关资源
      最近更新 更多