php 论坛里面的分页问题

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 论坛里面的分页问题相关的知识,希望对你有一定的参考价值。

论坛里面的留言列表中,第一个条显示楼主的内容,后面的是回复的信息,那这里的分页是怎么做的呢,怎么让在显示信息列表的时候,第一条是楼主的信息呢,,求高人指点了

参考技术A PEAR::pager
分页的类

php Wordpress中的分页

1. Put this in functions.php:

<?php

/**
 * Pagination links for search and archives
 */
function get_pagination_links() {
    global $wp_query;
    $wp_query->query_vars['paged'] > 1 ? $current = $wp_query->query_vars['paged'] : $current = 1;
    $big = 999999999;

    return paginate_links( array(
        'base' => @add_query_arg('paged','%#%'),
        'format' => '?paged=%#%',
        'current' => $current,
        'total' => $wp_query->max_num_pages,
        'prev_next'    => true,
        'prev_text'    => __('« Previous Page'),
        'next_text'    => __('Next Page »'),
    ) );
}
?>

2. Put this in your template file:

<div class="navigation"><p><?php echo get_pagination_links(); ?></p></div>
<?php

  //setup new query
  $query = new WP_query( 
      array(
          'posts_per_page'    =>    10, // ??
          'post_type'            =>    'custom-post-type', // custom post type
          'paged' => get_query_var('paged'),
          'meta_key' => 'wpcf-meta-key',
          'orderby' =>  'meta_value title',
          'order' => ASC,
          'meta_value' => $meta_value,
          'location' => $currentLocation, // custom taxonomy
          'vendor-type' => $currentVendorType, // custom taxonomy
      )
  );
?>
<?php if ($query->have_posts()): ?>
  <?php while ($query->have_posts()) : $query->the_post(); ?>
    <!-- display posts -->
  <?php endwhile; ?>
<?php else: ?>
 <!-- fallback -->
<?php endif; ?>

<?php 
  $total_pages = $query->max_num_pages;  
  
  $args = array(
    'base'         => preg_replace('/\?.*/', '/', get_pagenum_link(1)) . '%_%', 
    'format'       => 'page/%#%',
    'current'      => max( 1, get_query_var('paged') ),
    'total'        => $total_pages,  
    'show_all'     => False,
    'end_size'     => 1,
    'mid_size'     => 2,
    'prev_next'    => False,
    'prev_text'    => __('« Previous'),
    'next_text'    => __('Next »'),
    'type'         => 'plain',
    'add_args'     => array(
                       'vendor-type' => get_query_var('vendor-type'),
                       'vendor-location' => get_query_var('vendor-location')
                      ),
    'add_fragment' => ''
  ); 
?>
<?php if($total_pages > 1): ?>
  <nav class="vendor-nav group">
    <h1 class="hidden">Blog Post Navigation</h1>

    <span class="older">
      <?php next_posts_link('<div class="circle"><span class="arrow-e"></span></div>', $blush_vendor_query->max_num_pages) ?>
    </span>
    
    
    <span class="paginate-links">
      <?php echo paginate_links( $args ); ?>
    </span>

    <span class="newer">
      <?php previous_posts_link('<div class="circle"><span class="arrow-w"></span></div>', $blush_vendor_query->max_num_pages) ?>
    </span>
  </nav>
<?php endif; ?>

//----------------------------------------------
//  Limit Posts Per Archive Page
//----------------------------------------------

function limit_posts_per_archive_page() {
  if(!is_admin()){
    if ( is_category() )
      $limit = 2;
    if ( is_tag() )
      $limit = 2;
    elseif ( is_search() ) 
      $limit = 2;
    else
      $limit = get_option('posts_per_page');
  }
  set_query_var('posts_per_archive_page', $limit);
}
add_filter('pre_get_posts', 'limit_posts_per_archive_page');

以上是关于php 论坛里面的分页问题的主要内容,如果未能解决你的问题,请参考以下文章

php中的分页显示

自定义archive.php页面中的分页

php分页原理,懂得的指教一下哈!

php中的分页限制数据但不在下一页显示

Day08论坛3---分页

PHP+MySQL高效的分页方法,如何优化LIMIT,OFFSET进行的分页?