我正在使用WP\\U查询显示类别内的帖子和选定的自定义术语(“健康可见性”在类别“文章”中)
我的代码:
<?php $catquery = new WP_Query( \'post_type=article&posts_per_page=4&article-visibility=fitness\' );
while($catquery->have_posts()) : $catquery->the_post();
?>
<article class="post home-post">
<a href="<?php the_permalink(); ?>">
<div class="post-thumbnail-img">
<?php the_post_thumbnail(\'small-thumbnail\'); ?>
</div>
<h2><?php the_title(); ?></h2>
</a>
<p class="post-info">
<?php the_time(\'F jS, Y\'); ?> |
<?php get_template_part(\'block-athlete-archive\'); ?>
</p>
<p>
<?php echo get_the_excerpt(); ?>
<span class="readmore">
<br><a href="<?php the_permalink(); ?>">Read more »</a>
</span>
</p>
</article>
<?php endwhile; ?>`
现在,在我的归档页面上,我使用以下代码进行分页:
<div class="pagination">
<?php wpex_pagination(); ?>
</div>
我把它放在“endwhile”之后,它就起作用了。
WP\\U查询并非如此。
如何解决此问题?
SO网友:Owais Alam
将以下代码放入函数中。php
# +++++++++++++++++++++++++++++++Pagination ++++++++++++++++++++++++++++++++++++++
function kriesi_pagination($pages = \'\', $range = 2)
{
$prev = __(\'« Prev\');
$next = __(\'Next »\');
$showitems = ($range * 2)+1;
global $paged;
if(empty($paged)) $paged = 1;
if($pages == \'\') {
global $wp_query;
$pages = $wp_query->max_num_pages;
if(!$pages) {
$pages = 1;
}
}
if(1 != $pages) {
echo "<ul class=\'pagination\'>";
if($paged > 2 && $paged > $range+1 && $showitems < $pages && false)
echo "<li><a href=\'".get_pagenum_link(1)."\'>«</a></li>";
if($paged > 1 && $showitems < $pages)
echo "<li><a href=\'".get_pagenum_link($paged - 1)."\'>$prev</a></li>";
for ($i=1; $i <= $pages; $i++) {
if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems )) {
echo ($paged == $i)? "<li class=\'active\'><a href=\'javascript:void(0)\'>".$i."</a></li>":"<li class=\'inactive\'><a href=\'".get_pagenum_link($i)."\'>".$i."</a></li>";
}
}
if ($paged < $pages && $showitems < $pages)
echo "<li><a href=\'".get_pagenum_link($paged + 1)."\'>$next</a></li>";
if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages && false)
echo "<li><a href=\'".get_pagenum_link($pages)."\'>»</a></li>";
echo "</ul>\\n";
}
}
function kriesi_pagination2($pages = \'\', $range = 1)
{
$showitems = ($range * 2)+1;
global $paged;
if(empty($paged)) $paged = 1;
if($pages == \'\')
{
global $wp_query;
$pages = $wp_query->max_num_pages;
if(!$pages)
{
$pages = 1;
}
}
if(1 != $pages)
{
echo "<div class=\'pagination\'>";
if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href=\'".get_pagenum_link(1)."\'>«</a>";
if($paged > 1 && $showitems < $pages) echo "<a href=\'".get_pagenum_link($paged - 1)."\'>‹</a>";
for ($i=1; $i <= $pages; $i++)
{
if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
{
echo ($paged == $i)? "<span class=\'current\'>".$i."</span>":"<a href=\'".get_pagenum_link($i)."\' class=\'inactive\' >".$i."</a>";
}
}
if ($paged < $pages && $showitems < $pages) echo "<a href=\'".get_pagenum_link($paged + 1)."\'>›</a>";
if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo "<a href=\'".get_pagenum_link($pages)."\'>»</a>";
echo "</div>\\n";
}
}
# +++++++++++++++++++++++++++++++Pagination ++++++++++++++++++++++++++++++++++++++
将以下代码放在您的列表页上
<?php $catquery = new WP_Query( \'post_type=article&posts_per_page=4&article-visibility=fitness\' );
while($catquery->have_posts()) : $catquery->the_post();
?>
<article class="post home-post">
<a href="<?php the_permalink(); ?>">
<div class="post-thumbnail-img">
<?php the_post_thumbnail(\'small-thumbnail\'); ?>
</div>
<h2><?php the_title(); ?></h2>
</a>
<p class="post-info">
<?php the_time(\'F jS, Y\'); ?> |
<?php get_template_part(\'block-athlete-archive\'); ?>
</p>
<p>
<?php echo get_the_excerpt(); ?>
<span class="readmore">
<br><a href="<?php the_permalink(); ?>">Read more »</a>
</span>
</p>
</article>
<?php endwhile; ?>`
<div class="pagination">
<?php kriesi_pagination($catquery->max_num_pages); ?>
</div>
完成上述过程后,必须更新永久链接。