我只是稍微修改了一下您的代码以添加分页。。。。给你。。。。
这将是您自定义的帖子类型循环。。。。
<?php if ( get_query_var(\'page\') ) { $paged = get_query_var(\'page\'); } else if ( get_query_var(\'paged\') ) { $paged = get_query_var(\'paged\'); } ?>
<?php $LoopPortfolio = new WP_Query(array( \'post_type\' => \'portfolio\', \'paged\'=>$paged, \'posts_per_page\' => \'3\' )); ?>
<?php if($LoopPortfolio->have_posts()) : while($LoopPortfolio->have_posts()) : $LoopPortfolio->the_post(); ?>
<li class="col-lg-4 col-sm-4 view item <?php $terms = get_the_terms( get_the_ID(), \'portfolio_filter\' ); ?><?php if($terms) : foreach ($terms as $term) { echo $term->slug.\' \'; } endif; ?>">
<?php the_post_thumbnail("portfolio-image"); ?>
</li>
<?php endwhile;
pagination($LoopPortfolio->max_num_pages);
endif; wp_reset_query(); ?>
在函数中添加此函数。php文件。。。。
/// pagination
function pagination($pages = \'\', $range = 2)
{
$showitems = ($range * 2)+1;
if ( get_query_var(\'page\') ) {
$paged = get_query_var(\'page\');
} else if ( get_query_var(\'paged\') ) {
$paged = get_query_var(\'paged\');
} else {
$paged = 1;
}
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\\"><span>Page ".$paged." of ".$pages."</span>";
if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href=\'".get_pagenum_link(1)."\'>« First</a>";
if($paged > 1 && $showitems < $pages) echo "<a href=\'".get_pagenum_link($paged - 1)."\'>‹ Previous</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)."\\">Next ›</a>";
if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo "<a href=\'".get_pagenum_link($pages)."\'>Last »</a>";
echo "</div>\\n";
}
}
在CSS文件中添加此CSS。。。。。
/*******************/
.pagination {
clear:both;
padding:20px 0;
position:relative;
font-size:11px;
line-height:13px;
}
.pagination span, .pagination a {
display:block;
float:left;
margin: 4px 4px 4px 0;
padding:9px 12px 8px 12px;
text-decoration:none;
width:auto;
color:#fff;
background: #555;
}
.pagination a:hover{
color:#fff;
background: #3279BB;
}
.pagination .current{
background: #3279BB;
color:#fff;
}
您甚至可以将此代码用于主页(当自定义页面设置为主页时,分页通常不起作用)。因此,只需调用页面两次就可以解决此问题。如果你仍然需要帮助,请与我联系,如果我有时间,我必须帮助你。