|
魔扣币兑换比例:【 50以下 : ¥1 = 10 魔扣币 】丨【 50 - 100 :¥1 = 20 魔扣币】丨【 100以上:¥1 = 30 魔扣币 】
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
x
最近有个客户提到这样一个需要,就是首页先显示20篇文章,再每页加载10篇(点击加载更多),这样就与一般的分页不一样了,既要保证文章不重复,也要保证分页正确。请看下面代码:
- function MBThemes_offset_firstpage( $query ) {
- if ( $query->is_main_query() && !is_admin() && $query->get('post_type') != 'project') {
- $offset = 10;
- $query->set( 'post_type', 'post' );
- $query->set( 'post_status', 'publish' );
- $query->set( 'ignore_sticky_posts', '-1' );
- $ppp = get_option('posts_per_page');
-
- if (!$query->is_paged()) {
- $query->set('posts_per_page',$offset + $ppp);
- } else {
- $offset = $offset + ( ($query->query_vars['paged']-1) * $ppp );
- $query->set('posts_per_page',$ppp);
- $query->set('offset',$offset);
- }
- }
- }
- add_action('pre_get_posts','MBThemes_offset_firstpage');
- function MBThemes_offset_firstpage_pagination( $found_posts, $query ) {
- $offset = 10;
- if( $query->is_main_query() && !is_admin() && $query->get('post_type') != 'project') {
- $found_posts = $found_posts - $offset;
- }
- return $found_posts;
- }
- add_filter( 'found_posts', 'MBThemes_offset_firstpage_pagination', 10, 2 );
复制代码 来自:http://wordpress.stackexchange.com/questions/155758/have-different-number-of-posts-on-first-page
|
|