带分页的Wordpress自定义循环
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了带分页的Wordpress自定义循环相关的知识,希望对你有一定的参考价值。
<?php $blog = new WP_Query(); 'posts_per_page' => 5, 'paged' => $paged ); $blog->query($args); if($blog->have_posts()): while ($blog->have_posts()): $blog->the_post(); // Sets up the post ?> <h2><a href="<?php the_permalink() ?>"><?php the_title() ?></a></h2> <?php the_excerpt() ?> <?php endwhile; /* ----------------------- FUNCTION IS BELOW ----------------------- */ wp_pagination_nav($blog, $paged); wp_reset_query(); endif; ?> <?php /* -------------------------------------- ADD PAGINATION FUNCTION TO YOUR FUNCTIONS.PHP FILE -------------------------------------- */ function wp_pagination_nav($loop, $paged){ if($loop->max_num_pages>1): echo '<div class="pagination">'; if ($paged > 1): echo '<a href="?paged='.($paged-1).'"><</a> '; endif; for($i=1;$i<=$loop->max_num_pages;$i++){ if($paged==$i || ($i==1 && $paged == 0)){ $class = "selected"; } else { $class = ''; } echo '<a href="?paged='.$i.'" class="'.$class.'">'.$i.'</a> '; } if($paged < $loop->max_num_pages): $nextpage = $paged+1; if($paged == 0) $nextpage = 2; echo '<a href="?paged='.$nextpage.'">></a> '; endif; echo '<div class="clear"></div></div>'; endif; } ?>
以上是关于带分页的Wordpress自定义循环的主要内容,如果未能解决你的问题,请参考以下文章