我从“高级”Wordpress主题中获取了以下分页代码,试图将其集成到自定义主题中,但似乎无法使其正常工作:
在博客中。php页面模板,我有循环:
$paged = ( get_query_var( \'paged\' ) ) ? get_query_var( \'paged\' ) : 1;
$args=array(
\'paged\' => $paged,
\'post_type\' => \'post\',
\'posts_per_page\' => \'1\',
\'order\' => \'DESC\',
\'orderby\' => \'date\',
);
$wp_query = new WP_query($args);
if ( $wp_query -> have_posts() ) :
$j = 1;
while ($wp_query -> have_posts()): $wp_query -> the_post();?>
CONTENT HERE
<?php endwhile;prestigo_SPaginate();endif;?>
其功能是:if(!function_exists(\'prestigo_SPaginate\')){
function prestigo_SPaginate()
{
$currentPage = null;
$totalPage = null;
global $wp_query;
$currentPage = intval(get_query_var(\'paged\'));
if(empty($currentPage))
{
$currentPage = 1;
}
$totalPage = intval(ceil($wp_query->found_posts / intval(get_query_var(\'posts_per_page\'))));
if($totalPage <= 1)
{
return \'\';
}
$paginateResult = \'<!-- PAGINATION -->
<ul class="pagination clearfix">\';
if ($currentPage > 1)
{
$paginateResult .= \'<li class="pull-left"><a href="\'.get_pagenum_link($currentPage - 1).\'"><i class="fe arrow_carrot-left"></i></a></li>\';
}elseif ($currentPage = 1)
{
$paginateResult .= \'<li class="pull-left"><a href="javascript:void(0);"><i class="fe arrow_carrot-left"></i></a></li>\';
}
$paginateResult .= prestigo_ListLink(1, $totalPage, $currentPage);
if ($currentPage < $totalPage)
{
$paginateResult .= "<li class=\'pull-right\'><a href=\'" . get_pagenum_link($currentPage + 1) . "\' class=\'spaginate-next\'><i class=\'fe arrow_carrot-right\'></i></a></li>";
}elseif($currentPage = $totalPage){
$paginateResult .= "<li class=\'pull-right\'><span class=\'spaginate-next\'><i class=\'fe arrow_carrot-right\'></i></span></li>";
}
$paginateResult .= "</ul><!-- //PAGINATION -->";
echo $paginateResult;
return $paginateResult;
}
}
if(!function_exists(\'prestigo_ListLink\')){
function prestigo_ListLink($intStart, $totalPage, $currentPage)
{
$pageHidden = \'<span class="spaginate-hidden">... </span>\';
$linkResult = "";
$hiddenBefore = false;
$hiddenAfter = false;
for ($i = $intStart; $i <= $totalPage; $i++)
{
if($currentPage === intval($i))
{
$linkResult .= \'<li class="active"><a href="\'.get_pagenum_link($i).\'">\'.$i.\'</a></li>\';
}
else if(($i <= 6 && $currentPage < 10) || $i == $totalPage || $i == 1 || $i < 4 || ($i <= 6 && $totalPage <= 6) || ($i > $currentPage && ($i <= ($currentPage + 2))) || ($i < $currentPage && ($i >= ($currentPage - 2))) || ($i >= ($totalPage - 2) && $i < $totalPage))
{
$linkResult .= \'<li><a href="\'.get_pagenum_link($i).\'">\'.$i.\'</a></li>\';
if($i <= 6 && $currentPage < 10)
{
$hiddenBefore = true;
}
}
else
{
if(!$hiddenBefore)
{
$linkResult .= $pageHidden;
$hiddenBefore = true;
}
else if(!$hiddenAfter && $i > $currentPage)
{
$linkResult .= $pageHidden;
$hiddenAfter = true;
}
}
}
return $linkResult;
}
}
不幸的是,分页显示了出来,但单击第2页显示的帖子与第1页显示的帖子相同。任何建议都很好,谢谢。