七牛源码默认解压密码xxxile.com
首页,在php里加上相关代码:
WordPress posts_per_page如何将第一页的文章数设置成与其他页的数量不同
最近有个客户提到这样一个需要,就是首页先显示20篇文章,再每页加载10篇(点击加载更多),这样就与一般的分页不一样了,既要保证文章不重复,也要保证分页正确。请看下面代码: function MBThemes_offset_firstpage( $query ) { if ( $query->is_main_query() && !is_admin() && $query->get(‘post
<div class="article-list mobantu" id="article-list"> <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args = array( 'caller_get_posts' => 1, 'paged' => $paged ); query_posts($args); while ( have_posts() ) : the_post(); get_template_part( 'content', get_post_format() ); endwhile; wp_reset_query(); ?> </div> <?php $next_page = get_next_posts_link('加载更多'); if($next_page) echo '<div class="article-paging mobantu">'.$next_page.'</div>'; ?>
然后,在js里加上相关代码(条件需要加载了jquery,且网站使用了伪静态分页):
$('.article-paging > a').on('click',function(){ //点击实现加载更多,你可以凭证自己需要改成下拉自动加载 var next_url = $(this).attr("href"); var next_text = $(this).text(); if(next_text == '加载更多'){ $(this).text('加载中...'); $.ajax({ type: 'get', url: next_url + '#article-list', success: function(data){ result = $(data).find("#article-list .article-item"); next_link = $(data).find(".article-paging > a").attr("href"); //$(this).attr("href", next_url); if (next_link != undefined){ $('.article-paging > a').attr("href", next_link); $('.article-paging > a').text('加载更多'); }else{ $(".article-paging").remove(); } $(function(){ $("#article-list").append(result.fadeIn(300)); $('.thumb').lazyload({ data_attribute: 'src', placeholder: _BGJ.uri + '/static/img/thumbnail.png', threshold: 400 }); }); $(function() { if (next_url.indexOf("page") < 1) { $("#article-list").html(''); } $("#article-list").append(result.fadeIn(200)); }); } }); } return false; });
搞定!着实这次用这种方式实现无限加载主要是为了另一个高级功效做准备的~~