PHP Wordpress自定义循环与分页
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP Wordpress自定义循环与分页相关的知识,希望对你有一定的参考价值。
<?php
$blog = new WP_Query();
$args = array(
'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;
}
?>
以上是关于PHP Wordpress自定义循环与分页的主要内容,如果未能解决你的问题,请参考以下文章
css 自定义WP_Query与分页循环
PHP WordPress:自定义循环w /分页
带分页的Wordpress自定义循环
javascript JS:自定义幻灯片与分页
php 自定义帖子类型分页WordPress
PHP wordpress分页自定义查询