对于wordpress实现点击加载更多的方法,目前网络上用的较多的方法采用一款WordPress插件Infinite Scroll来实现的,大江网络工作室也是采用这个方法进行了测试,发现用起来并不是想象的那样好,于是研究了一个纯代码实现的方法,下面分享给大家。
- <?php
-
- $item_per_page = 9;
-
- $page_number = isset($_GET['paged']) ? $_GET['paged'] : 1;
-
-
- if(!is_numeric($page_number)){
- header('HTTP/1.1 500 Invalid page number!');
- exit();
- }
-
-
- $position = ($page_number * $item_per_page);
-
- $id = $_GET['cat'];
-
- if($id==2){$sql = "SELECT ID,post_title,post_content,post_date,post_name FROM wp_posts,wp_term_relationships,wp_term_taxonomy WHERE ID=object_id AND wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id AND post_type='post' AND post_status = 'publish' AND wp_term_relationships.term_taxonomy_id in(7,11,10,19,8,17,18) AND taxonomy = 'category' ORDER BY ID DESC LIMIT 0, $position ";}else{
-
- $sql = "SELECT ID,post_title,post_date,post_content,post_name FROM wp_posts,wp_term_relationships,wp_term_taxonomy WHERE ID=object_id AND wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id AND post_type='post' AND post_status = 'publish' AND wp_term_relationships.term_taxonomy_id = $id AND taxonomy = 'category' ORDER BY ID DESC LIMIT 0, $position ";}
-
- global $wpdb;
- $rs = $wpdb->get_results($sql);
-
- foreach($rs as $cat)
-
-
- {?>
-
-
- <div class="Case_list"> <a href="?p=<?php echo $cat->ID;?>" class="photo" ><img src="<?php $timthumb_src = wp_get_attachment_image_src( get_post_thumbnail_id($cat->ID),'full');
- echo $timthumb_src[0] ;
- ?>" alt="<?php echo get_post($cat->ID)->post_title;?>" width="250"/></a> <strong>
- <?php echo get_post($cat->ID)->post_title;?>
- </strong> <span class="time">
- <?php echo get_post($cat->ID)->post_date; ?>
- </span> </div>
-
- <?php }?>
-
- </div>
- <!-- CaseList结束 -->
- <span class="morecase">
- <div id="results"></div>
-
- <?php next_posts_link(__('+ 更多'));
- <!--<a href="#">+ 更多</a></span>-->
-
- </div>
- <!-- neirong结束 -->
- <span class="clear"></span>
- <!-- 清除浮动 -->
- </div>
- </div>
-
-
- <!-- container结束 -->
-
-
- <?php
-
- if($page_number!=1){?>
-
- <script type="text/javascript">
- $(document).ready(function() {
-
- $("body").scrollTop($("body")[0].offsetHeight);
-
- });
- </script>
- <?php }?>